Wednesday, October 17, 2007

Tips for Developer

Disabling a Button Until Processing is Complete

Here's the scenario - let's say you have an Insert subroutine, called 'doInsert'. You want to immediately disable the Submit button, so that the end-user won't click it multiple times, therefore, submitting the same data multiple times.

For this, use a regular HTML button, including a Runat="server" and an 'OnServerClick' event designation - like this:

<INPUT id="Button1" onclick="document.form1.Button1.disabled=true;" type="button" value="Submit - Insert Data" name="Button1" runat="server" onserverclick="doInsert"&rt;

Then, in the very last line of the 'doInsert' subroutine, add this line:

Button1.enabled="True"


There are three ways to add Javascript attributes to a particular ASP.Net Server control:

1. button1.Attributes.Add("OnClick", "document.form1.txtName.focus();")
2. button1.Attributes("OnClick")="document.form1.txtName.focus();"
3. button1.clientclick="function name"";

No comments: