I have the following problem. I have one form to input customer data. After that, the form will give the user message to indicate that it has been done successfully:
ScriptManager.RegisterStartupScript(this, GetType(), "Success",
"alert('Successfully input');", true);
Then, it will reload the page using the following:
Response.Redirect("customer_data.aspx");
The problem that I have is that the first command does not work if I put the second one. If remove the second one, it works fine. I have tried even to use:
try
{
ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('Successfully input');", true);
}
finally
{
Response.Redirect("customer_data.aspx");
}
but again the first command does not work. Please help.
That's because ASP.NET shields you from understanding what happens on client
Response.Redirect("customer_data.aspx");
Sends out http header
Location=customer_data.aspx
And
ScriptManager.RegisterStartupScript(this, GetType(), "Success",
"alert('Successfully input');", true);
Renders
<script type="text/javascript">
alert('Successfully input');
</script>
at the end of page. Naturally if location is set in http header, browser performs redirect and scripts on page are not executed. You can perform the redirection in javascript after displaying the alert:
ScriptManager.RegisterStartupScript(this, GetType(), "Success",
"alert('Successfully input');location.href='customer_data.aspx'", true);
I think the Response.Redirect to the same page is being detected as causing a loop. You can try reloading using script instead:
ScriptManager.RegisterStartupScript(this, GetType(), "Success",
"alert('Successfully input');window.location.reload(true);", true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With