asp.net 2.0中的Cross PAGE REQUEST

來源:互聯網
上載者:User

大家還記得吧,在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的方法,就可以接受前一個頁面中控制項的內容了。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.