1
votes

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 ;

    }
2
Note that you do not need javascript: within an event handler. Not an answer, just to save you some typing.Heretic Monkey

2 Answers

1
votes

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.

0
votes

This should work:

OnClientClick="return processHolidayDates();"