Asp.Net - transfer data cross page

Scenario

There are two pages: page1 and page2. In the page one, there are only a select and submit button, we want to transfer the select value to page two.

solution:

  1. Query string, in the page1.aspx.cs, coding submit button click event,  as below:

        void btnSubmit_Click(object sender, EventArgs e)

        {

                Response.Redirect("/page2.aspx?v=" + this.ddlT.SelectedItem.Value);

                or

                Server.Transfer(/"page2.aspx?v=" + this.ddlT.SelectedItem.Value);

        } 

      in the page2.aspx.cs

      void Page_Load(object sender, EventArgs e)

      {

        var vString = Request.QuertString["v"].toString();

        ...

      }

   2. use PreviousPageType property

    in the page1.aspx.cs

    void Page_Load(object sender, EventArgs) 

   {

        btnSubmit.PostBackUrl = "page2.aspx";

   }

   public DropDownList DdlT

   {

        get

        {

             return this.ddlT;

        }

   }

   in the page2.aspx, add below page property

  <%@ PreviousPageType VirtualPath="page1.aspx"%>

  in the page2.aspx.cs

   void Page_Load(object sender, EventArgs e)

  {

      var ddlTValue = PreviousPage.DdlT.SelectedItem.Value;

  }

 

转载于:https://www.cnblogs.com/AndrewZhang/archive/2012/03/06/1759283.html

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页