Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Michel http://michelc.wordpress.com/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

How to work around the "double-click" problem

This is a generic method to avoid "double-click" effect where a user click many times to validate. The button is hidden when the user clicks it. In order to not update all forms, the trick is applied to the Render event of the page.
protected override void Render(HtmlTextWriter output) {
    // Get normal html ouput
    StringBuilder stringBuilder = new StringBuilder();
    StringWriter stringWriter = new StringWriter(stringBuilder);
    HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
    base.Render(htmlWriter);
    string html = stringBuilder.ToString();
    // Enhance submit buttons
    string onclick1 = "\"if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();";
    string onclick2 = "\"this.style.display='none';";
    html = html.Replace("onclick=" + onclick1, "onclick=" + onclick2 + onclick1.Substring(1));
    // Render updated html
    output.Write(html);
}

window.onbeforeunload

window.onbeforeunload = function (evt) {
  var message = 'Are you sure you want to leave?';
  if (typeof evt == 'undefined') {
    evt = window.event;
  }
  if (evt) {
    evt.returnValue = message;
  }
  return message;
}

http://www.highdots.com/forums/archive/index.php/t-66363.html
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS