I faced with situations where users click a button on a web
application, and before the request was processed and response comes to the client
user clicks again. This may produce inconsistent and unexpected results. A
calculation will be performed twice or an entry is posted twice.
I’m working with ASP.NET web application coded with C#.
·
First ‘OnClientClick‘
event is set to disable the button.
-OnClientClick="onclick=this.disabled=true;"
·
The ‘UseSubmitBehavior’
attribute is set to false, that will include the ‘OnClick’ event to _dopostbak script
method rather than just submitting the page on button click
-UseSubmitBehavior="False"
So the button would look like this
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="False" OnClientClick="onclick=this.disabled=true;" />
The HTML output of it
will render to something like this
<input name="Button1"
id="Button1" onclick="onclick=this.disabled=true;
__doPostBack('Button1','')" type="button"
value="Button"/>
And that it the button
is disabled onclick and will be enabled back on when the response comes.
Note:
You might get a script
error if you use this on Internet Explorer 10 browser with .NET Framework 4.
This is due to browser definition mismatch. You can fix this by installing the
Hotfix provided here by
Microsoft.
Very useful and informative blog. Thank you so much for these kinds of informative blogs.
ReplyDeletewho provides seo services and e-commerce development services.
website designing in gurgaon
best website design services in gurgaon
web company in delhi
web desiging company
web design & development banner
web design & development company
web design & development services
web design agency delhi
web design agency in delhi
web design and development services
web design companies in delhi
web design company delhi
web design company in delhi
web design company in gurgaon
web design company in noida
web design company list
web design company services
web design company website
web design delhi
web design development company
web design development services
web design in delhi
web design service
web design services company
web design services in delhi
web designer company
web designer delhi
web designer in delhi
web designers delhi
web designers in delhi
web designing & development
web designing advertisement
web designing and development
web designing and development company
web designing and development services
web designing companies in delhi
web designing company delhi
web designing company in delhi
web designing company in gurgaon
web designing company in new delhi