Ah. I had the same issue in dev too, I just put a breakpoint on my code so the page would hang until I let it continue, giving me time to ensure the button would display the message. If you really want to see it work without a breakpoint, try this:
<%@ Page Language="VB"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default"%>
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
<title>Disable Test</title>
<script type="text/javascript"
FUNCTION disableButton(button, resetDelay)
{
button.oldonclick = button.onclick;
button.onclick=noClick; //new FUNCTION("return false;";
setTimeout("enableButton('" button.id + "');" resetDelay);
}
FUNCTION noClick()
{
alert("Chill - You already submitted this page once. Submitting it twice isn't going to make the server go faster. Quit hitting the freakin' button!";
RETURN false;
}
FUNCTION enableButton(buttonId)
{
var button = document.getElementById(buttonId);
IF(button!=NULL)
{
button.onclick = button.oldonclick;
}
}
</script>
</head>
<body>
<form id="form1"runat="server"
<asp:Button runat="server"ID="mybutton"TEXT="Click Me"OnClientClick="disableButton(this,5000);"/>
<asp:Label runat="server"ID="myLabel"/>
</form>
</body>
</html>
and this for the code behind:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub mybutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mybutton.Click
System.Threading.Thread.Sleep(5000)
Dim counter As Integer
If ViewState("TEST") Is Nothing Then
counter = 0
Else
counter = DirectCast(ViewState("TEST"), Integer)
End If
counter += 1
myLabel.Text = counter.ToString()
ViewState("TEST") = counter
End Sub
End Class
This displays the click count in a label, but the button code forces the thread to sleep 5 seconds before processing, which makes your page "hang" for a few seconds so you can test out the button functionality. Just remember if you put a sleep call in your actual code -- take it out before you deploy it to production =]
Damon Armstrong, Technology Consultant
[
Blog] [
Articles]