OnClientClick overwrites generated OnClick JS code

Last post 07-08-2009 1:22 AM by TechFriend. 2 replies.

Sort Posts:

  • OnClientClick overwrites generated OnClick JS code

    07-07-2009, 3:13 PM
    • Member
      16 point Member
    • Mark Barnes
    • Member since 12-29-2006, 7:57 PM
    • Posts 44

    I have an interesting problem that I am trying to figure out.   I am following some code examples and for the life of me I can't figure out why I am getting entirely different results even though they are using the same libraries.

    The code example specifies OnClientClick declaritively:

    <asp:Button ID="Button" runat="server" Text="Click Me" OnClientClick="disableSubmit();return false;"
                OnClick="Button_Click" />

    View source gives me this:

    <input type="submit" name="Button" value="Click Me" onclick="disableSubmit();return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="Button" /><br />


    On my code I do the same thing:

    <asp:Button ID="ValidateButton" runat="server" OnClientClick="disableSubmit();return false;" OnClick="ValidateButton_Click" Text="Validate" />

    but it gives me this:

    <input type="submit" name="ValidateButton" value="Validate" onclick="disableSubmit();return false;" id="ValidateButton" />


    It appears that the ASP.NET generated gibberish isn't appended to my code like the way it does on his/her code.  What's happening here?


  • Re: OnClientClick overwrites generated OnClick JS code

    07-08-2009, 1:10 AM
    • Member
      10 point Member
    • preethi_sam
    • Member since 03-02-2007, 5:30 PM
    • Posts 9

    If you have any validator control on the page then ASP.NET appends the "gibberish" to the button tag.

  • Re: OnClientClick overwrites generated OnClick JS code

    07-08-2009, 1:22 AM
    Answer
    • Member
      262 point Member
    • TechFriend
    • Member since 04-28-2009, 5:48 AM
    • Posts 43

    Hello Friend,

    You are misunderstanding the concept.

    Logically when you add a OnClientClick event it indicates that you have some client side validation/checks to be made. This validation/checks will return true if you find what is valid else return false. Now if you get the validation proper and return true; now the server side code needs to be executed. So, this is the way how it manages for you. Pretty Simple Friend.

    Please Mark as Answer if this reply helps you :)
    Filed under:
Page 1 of 1 (3 items)