This is a migrated thread and some comments may be shown as answers.

When I return true in asp:Button OnClientClick it doesn't postback form.

8 Answers 2193 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
varlo
Top achievements
Rank 1
varlo asked on 17 Oct 2010, 04:06 PM
When I return true in asp:Button OnClientClick it doesn't postback form.
I have
<asp:Button ID="btnReplace" runat="server" OnClientClick="return confirm('Are you sure?');" Text="Replace Schedule"></asp:Button>
inside of <asp:Panel ID="pnlMeetingDetails" runat="server">
and pabel is inside of RadAjaxManager
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="pnlMeetingDetails">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="pnlMeetingDetails" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
When I click btnReplace and select Ok in confirm dialog it doesn't make postback and server event btnReplaceSchedule_Click(object sender, EventArgs e) isn't called. If I remove OnClientClick in btnReplace it works fine. How to make client confirm script work together with RadAjaxManager?

8 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 18 Oct 2010, 04:49 PM
Hi Viktor,

I recommend that you review the following article for more information about how to provide a confirmation dialog to the users and initiate an AJAX request if accepted.
Client confirmation and AJAX

Kind regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Brad
Top achievements
Rank 1
answered on 15 Nov 2010, 06:47 PM
So in essense - returning anything cancels the PostBack.... regardless if it's "return true;"... Correct?  I was just fighting this very same issue where I was using OnClientClick="return MyFunction();" and it was always cancelling the PostBack even when the value returned from the function was "return true;"...  So this behaves almost like returning a value in the window before unload event...
0
Cori
Top achievements
Rank 2
answered on 16 Nov 2010, 02:10 PM
Hello Brad,

In the help topic Pavlina posted, you're supposed to change the OnClientClick property to look like this:

<asp:Button ID="Button2" runat="server" OnClientClick="if (!confirm('Are you sure?')) return false;" />  

Did that not work for you?
0
Pavlina
Telerik team
answered on 16 Nov 2010, 04:29 PM
Hi Cori,

To display a confirmation dialog that prompts the user whether a selected action should be executed (from a button in a template), you need to invoke the confirm javascript method (or use radConfirm for a confirmation dialog that uses skins). If the user chooses the negative option in the confirmation dialog, you should return false from the OnClientClick event handler of the button. Review this help topic for more information.

Best wishes,

Pavlina
the Telerik team

 

Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Brad
Top achievements
Rank 1
answered on 17 Nov 2010, 05:11 PM
Cori -

What I was trying to convey (for the benefit of others mainly) was that I had a function like below...

<asp:Button OnClientClick="return MyFunction();" />
  
function MyFunction() {
    return confirm("Do this?");
}

The problem was that returning anything (regardless of true/false) was causing the post-back to be cancelled...  it wasn't until I changed to the version that only returned false if necessary that it began to work as expected... so yes the code below works...

<asp:Button OnClientClick="if (!MyFunction()) return false;" />

So what I wanted to convey was that "returning true" though it seems intuitive - doesn't behave as expected...
0
Rodrigo
Top achievements
Rank 1
answered on 23 Jan 2013, 02:16 PM
"The problem was that returning anything (regardless of true/false) was causing the post-back to be cancelled..."

I have the same problem.

Ok, found a solution: OnClientClick="if(!myFunc()) return false;"
0
Qais
Top achievements
Rank 1
answered on 14 Jun 2013, 04:08 PM
Thanks. Great response. This issue took me a while to figure out.
0
Mayuresh
Top achievements
Rank 1
answered on 25 Apr 2019, 02:28 PM
Man! I was struggling with this for one whole day!! Thanks a lo!! :)
Tags
Ajax
Asked by
varlo
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Brad
Top achievements
Rank 1
Cori
Top achievements
Rank 2
Rodrigo
Top achievements
Rank 1
Qais
Top achievements
Rank 1
Mayuresh
Top achievements
Rank 1
Share this question
or