RadConfirm not Initializing on click of 'save' Button

3 posts, 0 answers
  1. Usman
    Usman avatar
    3 posts
    Member since:
    Aug 2015

    Posted 29 Sep 2015 Link to this post

    I have two RadButtons on a page, 'save' and 'save and exit' (see attachment..). When I click on the 'save and exit' button,  I get the expected behavior however when I click on the 'save' button, the functionality dose not work. It is strange because although the buttons do the exact same thing except that 'save and exit' redirects the user to a different page. 

    Why is the confirmation window not showing when I hit the save button?

    Please advice

    Thank you

  2. Usman
    Usman avatar
    3 posts
    Member since:
    Aug 2015

    Posted 29 Sep 2015 in reply to Usman Link to this post

    JavaScript:

    function ShowMessageAndRedirect() {
                    var oWnd = radalert('<%= alertsave %>', 330, 150, '<%= alertHead %>');
                    oWnd.add_close(OnSave);
                }
    function ShowMessage() {
                    var oWnd = radalert('<%= alertsave %>', 330, 150, '<%= alertHead %>');
                    oWnd.add_close(OnSaveAndRedirectToSamePage);
                }

    ASPX

    <telerik:RadButton runat="server" ID="uxSaveExit"  ValidationGroup="AddProduct" OnClick="Save_Click" Text="Save and Exit" Width="90px" TabIndex="9">
            </telerik:RadButton>

            <telerik:RadButton runat="server" ID="uxSave" ValidationGroup="AddProduct" OnClick="Save_Click" Text="Save" Width="90px" TabIndex="10">
            </telerik:RadButton>



    ASPX.CS

    if (Model.IsSavedOrUpdatedSuccess)
                {
                    if (((RadButton)(button)).Text == "Save and Exit")
                    {
                        PersistSearch();
                        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "ShowMessageAndRedirect(); ", true);
                    }
                    else if (((RadButton)(button)).Text == "Save")
                    {
                        PersistSearch();
                        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "ShowMessage(); ", true);
                        Response.Redirect("AddProduct.aspx?Mode=EDIT&Id=" + Model.Id);
                    }
                    else
                        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "ShowMessage();", true);
                }
                else
                    RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert", "radalert('Product failed to add', 370, 150, '" + FortegraResource.MessageHead + "');", true);
            }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 30 Sep 2015 Link to this post

    Hi Usman,

    The Response.Redirect call changes the HTTP header so the script is not registered at all, you can easily confirm this by adding a blocking browser alert that you will never see:

    else if (((RadButton)(button)).Text == "Save")
    {
        //PersistSearch();
        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert();ShowMessage(); ", true);
        Response.Redirect("AddProduct.aspx?Mode=EDIT&Id="/* + Model.Id*/);
    }

    I am attaching a sample page with some more ideas and explanations in the comments so you can use it as base for implementing this in your project.

    Perhaps the easiest approach is to redirect in the callback function of the RadAlert via JavaScript.

    Regards,

    Marin Bratanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top