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

RadConfirm not Initializing on click of 'save' Button

2 Answers 18 Views
Window
This is a migrated thread and some comments may be shown as answers.
Usman
Top achievements
Rank 1
Usman asked on 29 Sep 2015, 05:34 PM

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 Answers, 1 is accepted

Sort by
0
Usman
Top achievements
Rank 1
answered on 29 Sep 2015, 05:36 PM
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);
        }
0
Marin Bratanov
Telerik team
answered on 30 Sep 2015, 06:25 AM

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
Tags
Window
Asked by
Usman
Top achievements
Rank 1
Answers by
Usman
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or