admin 管理员组文章数量: 1086019
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 mand 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 mand does not work. Please help.
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 mand 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 mand does not work. Please help.
Share Improve this question edited Mar 10, 2014 at 21:17 Michael Petrotta 61k27 gold badges152 silver badges181 bronze badges asked Mar 10, 2014 at 19:57 user2103335user2103335 634 silver badges13 bronze badges3 Answers
Reset to default 7That'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);
You can use something like this:
string answer = "Success";
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect",
"alert('" + answer + "'); window.location.href='index.aspx';", true);
本文标签: cResponseRedirect eliminates the script manager actionStack Overflow
版权声明:本文标题:c# - Response.Redirect eliminates the script manager action - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744082082a2530436.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论