代码改变世界

Asp.net中的页面传值

2011-04-14 08:50  迪奥  阅读(343)  评论(0编辑  收藏  举报

Asp.net中的页面传值方法:

        Url传值:

        Session

        Cookie

        Application

        Response.Redirect()传值

        最后在另外一个页面获得当前页面的控件中的值,在这里重点讲一下

首先在asp.net中只有Button linkButton imgButton有postbackUrl属性可以用来跨页传递控件的值

<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="index.aspx" />

Index.aspx:

  if(Page.PreviousPage!=null)

     {

        if(Page.PreviousPage.IsCrossPagePostBack)

        {

            TextBox textControl=this.PreviousPage.FindControl("TextBox1") as TextBox;

 

            if(textControl.Text!=null)

             {

                 this.Label1.Text = textControl.Text;

             }

         }

    }

   PreviousPage:代表传递值的页面

IsCrossPagePostBack:判断页面是不是跨页传值

FindControl:获得控件的值