大家还记得吧,在ASP中,一个页面里,只要有一个Form表单,在POST后,就可以在另外一个表单里用REQUEST来接受了,而在ASP.NET 2.0中,咱们又可以这样做了,因为有了新的特性,叫做cross page request,可以实现这样的功能,代码如下,十分简单:crosspage1.aspx:<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div>
<asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
<asp:Button ID="Button1" Runat="server" Text="Button" PostBackUrl="crosspage2.aspx" />
</div>
</form></body></html>crosspage2.aspx: public void Page_Load() {
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack) {
TextBox textBox1 = PreviousPage.FindControl("TextBox1") as TextBox;
if (textBox1 != null)
Response.Write(textBox1.Text);
}
}哈哈,明白了吧?其中,我们利用button,linkbutton等控件的postbackurl属性,可以指定要将内容POST到哪一个表单中去,而在要接受内容的页面中,使用PreviousPage.findconrol的方法,就可以接受前一个页面中控件的内容了。
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18