Why is the warning not being executed?

I have a control, if the review already exists, if it exists, I want to warn the visitor that if the person clicks the OK / Yes button in the alert, the checkout will be overwritten, if the person hasn't clicked / canceled the review, refreshed. But that won't work, when debugging the alert line just passes by and updates without warning.

if (ReviewExist(StoreID, UserID) != 0)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "confirm('Are you sure?');", true);
    UpdateStoreReview(Description);
    Response.Redirect("Default");
}
else      
{
    AddStoreReview(Description);
}

      

+3


source to share


3 answers


This is because yours Response.Redirect

redirects the control to another page, which will ignore yours RegisterScript

.

What do you need to do if you are trying to achieve this on button click (refresh button) and then in Page_Load try

if(!IsPostBack)    
{
 btnUpdate.Attributes.Add("OnClick","confirm('Are you sure?');");
}

      



Then the above code can be changed to

if (ReviewExist(StoreID, UserID) != 0)
{
    UpdateStoreReview(Description);
    Response.Redirect("Default");
}
else      
{
    AddStoreReview(Description);
}

      

Note I think you need to redirect to Default.aspx; but you are missing .aspx in Response.Redirect

.

+8


source


You need script tags in your script.



ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "<script type='text/javascript'>confirm('Are you sure?');</script>", true);

      

+2


source


IF you are using ASP.net

<asp:Button ID="_btnSalvar" runat="server" Confirm="False" ConfirmType="None" Text="Are you sure?" Width="131px" OnClick="_btnSalvar_Click" />

      

+1


source







All Articles