2

I have this much

HTML

<asp:Button ID="btnSaveContest" runat="server" Text="Save &amp; Publish Contest" OnClientClick=" ValidateCreateContest();" ValidationGroup="ContestAdd" OnClick="btnSaveContest_Click" CausesValidation="false"/>

JavaScript

<script type="text/javascript">
    function ValidateCreateContest() {
        Page_ClientValidate();
        if (Page_IsValid) {
            alert('page is valid');
            $('#<%=btnSaveContest.ClientID%>').attr('disabled', 'disabled');
            __doPostBack('<%=btnSaveContest.ClientID%>', '')
            return true;
        }
        else {
            alert('not valid');      
            return false;
        }     

    }
</script>

It does post back to the page, but it does not go to the server side function btnSaveContest_Click. Why ?

3
  • I have had some troubles doing similar things to this. One solution I found was to do OnClientClick="ValidateCreateContest(); return isFormValid;", and then in the ValidateCreateContest(); function do isFormValid = true, isFormValid = false as required, with isFormValid being a global variable. Commented Sep 2, 2011 at 9:35
  • @Oliver :- It did postback, but it did not go to the btnSaveContest_Click function... ??? Commented Sep 2, 2011 at 9:37
  • first check if there is any javascript error in the page using error console. if you are checking it using a breakpoint then stop the project make a clean build and then again rebuild and run the project see if it helps and if this does not work try changing the default browser. Commented Sep 2, 2011 at 9:38

1 Answer 1

4

Don't use ClientID, use UniqueID

    if (Page_IsValid) {
        alert('page is valid');
        $('#<%=btnSaveContest.ClientID%>').attr('disabled', 'disabled');
        __doPostBack('<%= btnSaveContest.UniqueID %>', '')
        return true;
    }
    else {
        alert('not valid');      
        return false;
    }     

This question may be useful.

Sign up to request clarification or add additional context in comments.

4 Comments

@_onof would you please tell the difference between ClientId And UniqueId.please explore your answer a bit it will help OP.Thanks
@mraufk & onof:Thanks for your explanation and help links it will surely help me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.