问题描述
我是.net应用程序开发的新手.在我的项目中,我创建了一个表单,当我单击提交"按钮时,这些值已插入数据库中.如果成功插入,则我的表单将使用response.redirect(" home.aspx ).
I am new to .net application development. In my project i created one form ,when i click on submit button,those values inserted into data base.If it is successfully inserted,then my form navigated to another form using response.redirect("home.aspx").
但是在这种情况下,当单击提交"按钮时,值被插入到数据库中,但是没有显示警告消息,我的页面导航到了home.aspx页面.
But in this when is click on submit button,values are inserted into database,but with out showing the alert message ,my page navigated to home.aspx page.
但是我的要求是,它必须显示警报消息,单击警报框的确定"按钮后,它会导航到另一页.
But my requirement is,it should have to show the alert message,after click on alert box OK button then it is navigate to another page.
任何帮助表示赞赏
public static void ShowAlertMessage(string error)
{
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
error = error.Replace("'", "");
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + error + "');", true);
}
}
推荐答案
ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + error + "');window.location='pagename.aspx';", true);
您只需要在您的javascript函数中使用 window.loacation
进行重定向.删除 Response.Redirect()
.
you will have to redirect using window.loacation
in you javascript function only.Remove Response.Redirect()
.
Response.redirect是服务器端代码,它不等待执行客户端代码.如果我们将两个语句都写在客户端,那么它将正常工作.
Response.redirect is server side code and it does not wait to execute client side code. if we will write both statement on client side then it will work fine.
这篇关于如何在C#中的警报框“确定"按钮上编写动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!