`

asp.net 2.0中的Cross PAGE REQUEST

阅读更多

大家还记得吧,在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的方法,就可以接受前一个页面中控件的内容了。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics