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

发布于 2024-09-27 11:37:48 字数 3574 浏览 1 评论 0原文

我发现有时你想做的最简单的事情几乎不可能得到答案。我有一个在 Visual Studio 2005 中编程的 ASP.NET V2 中的 ASPX 页面。该 ASPX 页面有一个隐藏代码 ASXP.VB 页面,并绑定到 .master 文件。我有两个按钮 [Button_Process],它们最终将调用一个从 SQL 表中提取数据的程序——这里没有问题。 [Button_Process] 还将调用一个 7 秒的 JavaScript 计时器(足够时间进行提取)。我们正在做定时器延迟,所以会出现一个可爱的小图形,让使用该页面的人认为系统正在工作,而不是双击按钮——我知道还有其他方法可以做到这一点,但这是我们已知的方法) 。这里同样没有问题。单击 [Button_Process] 按钮七秒后,带有警报的测试会发送一条消息。到目前为止,世界上一切都很好。

我有第二个按钮 [Button_PM_Upload],在此期间隐藏。它最终将在单击按钮时调用一个程序,以从之前的按钮单击收集中获取信息,将其与第二个 SQL 表中的数据进行比较并更新第二个 SQL 表。我想做的就是在七秒结束后使第二个按钮可见。我的任务非常简单,但我在寻找解决方案时遇到问题。

在 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>

在代码页后面的 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

通过几天的阅读和研究,我发现计时器是客户端,后面的代码是服务器端,“两者从不说话”。网上的文章说,为了让第二个按钮可以被javascript“抓取”,我必须不说 (visible=false) 来在计时器之前最初使其不可见,计时器是服务器端的,并且不会在客户端提供按钮,我需要调整显示命令。该代码位于该按钮的 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" />

正如我哥哥在我们年轻时常说的那样,--“此时一切都很好”。文章的下一部分内容因作者而异。然而,所有人都有一个接近的解决方案,但没有告诉在哪里放置代码。我已经将它放在母版页的 Javascript 中的警报下。这是我得到的:

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

给我 -- 按钮保持隐藏

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

给我 -- 按钮保持隐藏

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

给我 -- 按钮保持隐藏

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

给我 -- 按钮保持隐藏

每当我用内联替换块(一个建议)时,所有四个代码行都会给出我得到同样的结果(什么也没有)。每当我用块替换可见(另一个建议)时,所有四个代码行都会给我相同的结果。每当我用内联替换块(另一个建议)时,所有四个代码行都会给我相同的结果。

我确实找到了这个例子,您将服务器代码放入 -- ("<%=Button_PM_Upload%>") --,但我得到的只是一个错误(无论我如何安排它),内容如下: BC30451: Name未声明“Button_PM_Upload”。

我的网站在项目的根目录下有母版页。根目录中还有一个名为 [PSC_Tools] 的文件夹。我的 ASPX 和 ASPX.VB 页面位于该文件夹中,我想知道这是否是一个简单的路径问题。不管是什么,我都处于停滞状态——有时最简单的事情却是最难找到代码的。 Ajax 工具是不可能的。该网站是在没有它们的情况下开发的,如果导入它们,它们会干扰运行该网站的配置文件。

我是否在某处缺少代码?我不是在进口东西吗?这与配置或 css 文件有关吗?我不知所措。我浏览了你们的网站,可以感受到从我的显示器中散发出来的智慧和经验的热量。希望我遵守提问规则,并且非常感谢您提供的任何帮助。作为帮助,您能否让我确切地知道代码应该放在哪里以及在哪个页面(ASPX、ASXP.VB、.master)上。

周末愉快

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. 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] will also call a javascript timer that goes for 7seconds (enough time for the extraction to happen). 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. Everything is good in the world up to this point.

I have a second button, [Button_PM_Upload], that is hidden during this time. 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. 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:

<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:

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. That code is located on the ASPX page for that button and looks like this in the source code:

<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. 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. 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.

My web site has the master page on the root of the project. Also on the root is a folder called [PSC_Tools]. My ASPX and ASPX.VB pages are in that folder and I'm wondering if maybe its a simple path problem. 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. 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? 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.

Have a great weekend

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薔薇婲 2024-10-04 11:37:48

有一个简单的解决方法:将按钮包裹在 div 中:

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

然后隐藏并显示 div。

如果您想禁用该按钮,请像这样使用 jQuery:

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

技巧是通过包装元素引用该按钮。

There is an easy workaround: Wrap the button in a div:

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

Then hide and show the div.

If you wanted to disable the button, use jQuery like this:

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

The trick is referencing the button through the wrapping element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文