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

8 posts, 0 answers
  1. varlo
    varlo avatar
    5 posts
    Member since:
    Nov 2006

    Posted 17 Oct 2010 Link to this post

    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?
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 18 Oct 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brad
    Brad avatar
    4 posts
    Member since:
    Oct 2008

    Posted 15 Nov 2010 Link to this post

    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...
  5. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 16 Nov 2010 Link to this post

    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?
  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 Nov 2010 Link to this post

    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.
  7. Brad
    Brad avatar
    4 posts
    Member since:
    Oct 2008

    Posted 17 Nov 2010 Link to this post

    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...
  8. Rodrigo
    Rodrigo avatar
    4 posts
    Member since:
    Nov 2012

    Posted 23 Jan 2013 Link to this post

    "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;"
  9. Qais
    Qais avatar
    1 posts
    Member since:
    Jun 2013

    Posted 14 Jun 2013 Link to this post

    Thanks. Great response. This issue took me a while to figure out.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017