1

I am working on an asp.net web forms project. I have an asp.net button which has both OnClientClick and onClick events. The OnClientClick event executes the javascript function processHolidayDates() which in turn shows a Telerik's Ok/Cancel message box. When the Ok button is clicked it will return true and if the Cancel button is clicked it will return false. So, when false is returned, I don't want the button click event to execute the server side code. However, the moment the message box is displayed already the code behind under the btnCreate_Click is executed. When I add "return false;" at the OnClientClick as in "OnClientClick="javascript:processHolidayDates(); return false " , the code behind is never executed even if I chose Ok in the message box. The following is my code on the aspx page

    <asp:button id="btnCreate" runat="server" Text="Create"  OnClientClick="javascript:processHolidayDates(); " onclick="btnCreate_Click"></asp:button> 
function processStartAndEndDates() {

        var oConfirm = radconfirm('Hello', callBackFn, 400, 300, null, 'Test');
    return oConfirm ;

    }
1
  • Note that you do not need javascript: within an event handler. Not an answer, just to save you some typing. Commented Mar 13, 2018 at 21:30

2 Answers 2

1

You could change your OnClientClick to

OnClientClick="return processHolidayDates();"

So that you will return false (and cancel the postback) if the user cancels the window.

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

Comments

0

This should work:

OnClientClick="return processHolidayDates();"

2 Comments

I tried it but didn't work. Whether I clicked ok or Cancel, the code behind is never reached!
Could you double check what's inside oConfirm? I bet that returns a component, and the final response is on callBackFn

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.