运用PreviousPage简化提交流程
若是一个page1.aspx向page2.aspx提交的流程,则在page2.aspx的顶部添加如下声明:
<%@ PreviousPageType VirtualPath="~/page1.aspx" %>
设置page1.aspx的PostbackUrl属性为~/page2.aspx。
假设page1.aspx的codebehind中有名为test()的方法,则在page2.aspx中可以这样调用:
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
return ((page1)PreviousPage).test();
}
顺便记录一下注册客户端脚本的方法:
static readonly string script = "<script language=\"javascript\">\n" +
"alert (\"Sorry, but we couldn't validate your credit card\");\n" + "</script>";
ClientScript.RegisterStartupScript(script.GetType(), "Error", script);
<%@ PreviousPageType VirtualPath="~/page1.aspx" %>
设置page1.aspx的PostbackUrl属性为~/page2.aspx。
假设page1.aspx的codebehind中有名为test()的方法,则在page2.aspx中可以这样调用:
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
return ((page1)PreviousPage).test();
}
顺便记录一下注册客户端脚本的方法:
static readonly string script = "<script language=\"javascript\">\n" +
"alert (\"Sorry, but we couldn't validate your credit card\");\n" + "</script>";
ClientScript.RegisterStartupScript(script.GetType(), "Error", script);