简体   繁体   English

在带有主文件的ASP.NET 2.0页面上使用Java Timer

[英]Java Timer use on an ASP.NET 2.0 page with Master File

I have found out that sometimes the simplest things you want to do are almost impossible to fund an answer for. 我发现有时您想做的最简单的事情几乎不可能为答案提供资金。 I have an ASPX page in ASP.NET V2 programmed in Visual Studio 2005. The ASPX page has a behind code ASXP.VB page and is tied to a .master file. 我在Visual Studio 2005中编程的ASP.NET V2中有一个ASPX页。ASPX页具有背后的代码ASXP.VB页,并绑定到.master文件。 I have two buttons [Button_Process] that will eventually call a program that will extract data from a SQL table -- no problem here. 我有两个按钮[Button_Process],它们最终将调用一个程序,该程序将从SQL表中提取数据-在这里没有问题。 [Button_Process] will also call a javascript timer that goes for 7seconds (enough time for the extraction to happen). [Button_Process]还将调用一个JavaScript计时器,该计时器持续7秒(提取足够的时间)。 We're doing the timer delay so a cute little graphic appears and makes the person using the page think the systems working and not to double-click the button -- I know there's other ways of doing this but this is our approach for know). 我们正在执行计时器延迟,因此会出现一个可爱的小图形,并使使用该页面的人认为系统正在运行,而不是双击按钮-我知道还有其他方法可以这样做,但这是我们知道的方法) 。 Again there is no problem here. 同样,这里没有问题。 test with an aleart delivers a message seven seconds after clicking the [Button_Process] button. 单击[Button_Process]按钮七秒钟后,用aleart测试会发送一条消息。 Everything is good in the world up to this point. 到目前为止,世界上一切都很好。

I have a second button, [Button_PM_Upload], that is hidden during this time. 我还有第二个按钮[Button_PM_Upload],在此期间处于隐藏状态。 It will eventually call a program on button-click to take the info from the previous button click collecting, compare it to data in a second SQL table and update the second SQL table. 最终,它将在单击按钮时调用一个程序,以收集上一次单击按钮收集的信息,将其与第二个SQL表中的数据进行比较,并更新第二个SQL表。 All I want to do is to make that second button visible after the seven seconds is up. 我要做的就是在七秒钟后使第二个按钮可见。 I very simple task but I am having problems finding the solution. 我的任务很简单,但是在寻找解决方案时遇到了问题。

In the master page between head tags is this timer code that works remarkably well: 在head标签之间的母版页中,此计时器代码非常有效:

<script type="text/javascript">
<!--
var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 7
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        alert("The timer is working properly")
        //document.getElementsByName ("Button_PM_Upload").style.display=
         "block";          
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
//-->
</script>

On the ASPX.VB behind code page is this code for that button click and it works very well too: 在ASPX.VB后面的代码页上,是该按钮单击的代码,它的效果也很好:

Protected Sub Button_Process_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Process.Click
    'This code fires of the timer in the master file
    ClientScript.RegisterStartupScript(GetType(Page), "Startup", "<script type=text/javascript>InitializeTimer()</script>")
End Sub

Through days of reading and research I found out that the timer is clientside and the behind code is Serverside and "never the two do talk". 经过几天的阅读和研究,我发现计时器是在客户端,后面的代码是在服务器端,并且“两者永远不要说话”。 Articles on the NET say that to make the second button "grabable" by the javascript, I must instead of saying (visible=false) to initially make it invisible prior to the timer , which is serverside and doesn't deliver the button clientside, I need to tweak the display command. NET上的文章说,要使第二个按钮可被javascript“抓取”,我必须说(visible = false)使其在timer之前不可见,该定时器在服务器端,并且不会在客户端传递按钮,我需要调整显示命令。 That code is located on the ASPX page for that button and looks like this in the source code: 该代码位于该按钮的ASPX页面上,并在源代码中如下所示:

<asp:Button ID="Button_PM_Upload" runat="server" Style="display: none; left: 632px;
position: absolute; top: 252px; z-index: 104;" Text="Upload to PartsMaster"
ToolTip="Change PR codes and Descriptions"  Width="147px" />

As my older brother use to say in our youth, -- "everything is hunky-dory at this point". 正如我的哥哥在我们青年时代所说的那样:“在这一点上,一切都是笨拙的”。 The next part that the articles say varies between authors. 文章说的下一部分在作者之间有所不同。 All do however have a close solution but do not tell where to place the code. 但是,所有人都有一个严密的解决方案,但不知道将代码放置在何处。 I have been placing it under the alert in the Javascript in the master page. 我一直将其放在母版页Javascript中的警报下。 Here is what I am getting: 这是我得到的:

document.getElementsByName("Button_PM_Upload").style.display="block";

gives me -- button stays hidden 给我-按钮保持隐藏

document.getElementsByName("Button_PM_Upload").style.display='block';

gives me -- button stays hidden 给我-按钮保持隐藏

document.getElementsByName('Button_PM_Upload').style.display='block';

gives me -- button stays hidden 给我-按钮保持隐藏

document.getElementsByName('Button_PM_Upload').style.display="block";

gives me -- button stays hidden 给我-按钮保持隐藏

Whenever I substitute block for inline (one suggestion) all four code lines give me the same result (nothing). 每当我用块代替内联(一个建议)时,所有四个代码行都给我相同的结果(什么都没有)。 Whenever I substitute block for visible (another suggestion) all four code lines give me the same result. 每当我用block代替可见的(另一个建议)时,所有四个代码行都给我相同的结果。 Whenever I substitute block with inline (another suggestion) all four codes lines give me the same result. 每当我用内联替换块(另一个建议)时,所有四个代码行都给我相同的结果。

I did find this example where you put server code in -- ("<%=Button_PM_Upload%>") --, but all I get is an error (no matter how I arrange it) that reads this: BC30451: Name 'Button_PM_Upload' is not declared. 我确实找到了将服务器代码放入-(“ <%= Button_PM_Upload%>”)-的示例,但我得到的只是一个错误(无论如何安排),其内容如下:BC30451:名称为'Button_PM_Upload '未声明。

My web site has the master page on the root of the project. 我的网站在项目的根目录上具有母版页。 Also on the root is a folder called [PSC_Tools]. 根目录上还有一个名为[PSC_Tools]的文件夹。 My ASPX and ASPX.VB pages are in that folder and I'm wondering if maybe its a simple path problem. 我的ASPX和ASPX.VB页面位于该文件夹中,我想知道它是否可能是一个简单的路径问题。 Whatever it is, I am a standstill -- sometimes the simplest things to do are the hardest to find code for. 无论是什么,我都停滞不前-有时最简单的事情是最难找到的代码。 Ajax tools are out of the question. Ajax工具是不可能的。 The site was developed without them and if imported in, they interfer with the config file running the site. 该站点是在没有它们的情况下开发的,如果将其导入,它们会干扰运行该站点的配置文件。

Am I missing code somewhere? 我在某处缺少代码吗? Am I not importing something? 我不导入东西吗? Does this have to do with the config or css files? 这与config或css文件有关吗? I'm at a loss. 我很茫然。 I came across your site and could feel the heat of collected intellect and experience exuding out from my monitor. 我碰到了您的站点,可能会感觉到收集到的智力的热度以及从监视器中渗出的经验。 Hope I followed the rules for asking a question and would very much appreciate any help you could give. 希望我遵守提出问题的规则,并非常感谢您能提供的任何帮助。 And as a help, coould you please let me know exactly where and on what page (ASPX, ASXP.VB, .master) the code should go. 作为帮助,您可以让我确切知道代码应该在什么地方以及在什么页面(ASPX,ASXP.VB,.master)上。

Have a great weekend 周末愉快

There is an easy workaround: Wrap the button in a div: 有一个简单的解决方法:将按钮包装在div中:

<div id="x"><asp:Button/></div>

Then hide and show the div. 然后隐藏并显示div。

If you wanted to disable the button, use jQuery like this: 如果要禁用该按钮,请使用jQuery,如下所示:

$('#x button').attr('disabled', 'disabled');

The trick is referencing the button through the wrapping element. 诀窍是通过包装元素引用按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM