Disable button after first click and client validate

Last post 05-12-2008 12:00 PM by AlexeySpirin. 6 replies.

Sort Posts:

  • Disable button after first click and client validate

    05-04-2008, 4:40 PM
    • Member
      21 point Member
    • AlexeySpirin
    • Member since 01-04-2008, 12:40 PM
    • Russia, Moscow
    • Posts 25

    Hello, friends!

    I have a trouble with disabling the button after first click and clicent validation.

    I found some solutions, but only one works fine. This solution from Angus Logan - http://msmvps.com/blogs/anguslogan/archive/2004/12/22/27223.aspx

    A put this code to may page:

    1    StringBuilder sbValid = new StringBuilder();
    2    sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");
    3    sbValid.Append("if (Page_ClientValidate('ResumeEdit') == false) { return false; }} ");
    4    sbValid.Append("this.src = '/images/wait.gif';");
    5    sbValid.Append("this.disabled = true;");
    6    sbValid.Append("document.all." + btnSend.UniqueID + ".disabled = true;");
    7    sbValid.Append(Page.ClientScript.GetPostBackEventReference(btnSend, btnSend.ID));
    8    sbValid.Append(";");
    9    btnSend.Attributes.Add("onclick", sbValid.ToString());

    It works fine in IE, but not works in Firefox.

    After click on button it disables and change image, and form submit to server. But event btnSend_Click not raised - only Page_Load method works. This problem in Firefox, in IE all works fine.

     Please help me resolve this problem.

    Thank you very much!

    Sorry, my English is bad. I can read, but i can't write good ;)
  • Re: Disable button after first click and client validate

    05-05-2008, 3:09 AM
    Answer
    • Participant
      1,266 point Participant
    • Mojtaabaa
    • Member since 04-29-2008, 6:54 AM
    • ایران
    • Posts 245
  • Re: Disable button after first click and client validate

    05-05-2008, 3:55 AM
    • Member
      21 point Member
    • AlexeySpirin
    • Member since 01-04-2008, 12:40 PM
    • Russia, Moscow
    • Posts 25

    Thank you very much!

    Sorry, my English is bad. I can read, but i can't write good ;)
  • Re: Disable button after first click and client validate

    05-05-2008, 8:31 AM
    • Member
      21 point Member
    • AlexeySpirin
    • Member since 01-04-2008, 12:40 PM
    • Russia, Moscow
    • Posts 25

    Where I can get ajaxcontrol toolkit clickonce button ? There is no this control in Toollkit...

    I need solution not for ajax, only for standard form sending. Thank you.

    Sorry, my English is bad. I can read, but i can't write good ;)
  • Re: Disable button after first click and client validate

    05-05-2008, 8:55 AM
    • Member
      523 point Member
    • navaneethkn
    • Member since 06-01-2007, 6:00 AM
    • India
    • Posts 141

    Hi,

    You can do this with javascript. Or just check this server control which wraps the functionalities.  

    Sincerely
    Navaneeth.K.N
    www.w3hearts.com

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: Disable button after first click and client validate

    05-06-2008, 2:01 AM
    Answer
    • Member
      21 point Member
    • AlexeySpirin
    • Member since 01-04-2008, 12:40 PM
    • Russia, Moscow
    • Posts 25

    Thank You, navaneethkn !

    But i found solution with Angus Logan's code - I modify it for Framework 2.0.

    Please, see this code block:

    1                StringBuilder sbValid = new StringBuilder();
    2                sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");
    3                sbValid.Append("if (Page_ClientValidate('ResumeEdit') == false) { return false; }} ");
    4                sbValid.Append("this.src = '/images/wait.gif';");
    5                sbValid.Append("this.disabled = true;");
    6                sbValid.Append(Page.ClientScript.GetPostBackEventReference(btnSend, btnSend.ID));
    7                sbValid.Append(";");
    8                btnSend.OnClientClick = sbValid.ToString();

    It work fine in IE, Opera and Firefox.

    Additionally you can add this code <img src="/images/wait.gif" style="width:1px;" /> in order to browser cache the "wait" image and display it immediately after click.

     
    Sorry, my English is bad. I can read, but i can't write good ;)
  • Re: Disable button after first click and client validate

    05-12-2008, 12:00 PM
    • Member
      21 point Member
    • AlexeySpirin
    • Member since 01-04-2008, 12:40 PM
    • Russia, Moscow
    • Posts 25

    I have one more problem. How I wrote in last message, code works fine. But, it works only when EnableEventValidation="false", if this property set to true, I have an error "Error validating request...." and recommendation to use ClientScriptManager.RegisterForEventValidation. How can i use it?

    I search for solution, but i see, that everybody says that EnableEventValidation="false" is only one. But i thinks, that this is bad idea, because it switch off validation of request.

    Thank you very much.

    Sorry, my English is bad. I can read, but i can't write good ;)
Page 1 of 1 (7 items)