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);
}
source to share
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
.
source to share