Transferring DropDownList values from one page to the next

前端 未结 3 485
梦如初夏
梦如初夏 2021-01-28 12:47

I have 2 pages, both with 3 similar DropDownLists. The first DropDownList needs to be populated before selecting the second, and the second before the third (which then populate

3条回答
  •  长情又很酷
    2021-01-28 13:47

    You can pass values from one page to the other using the PreviousPage parameter that asp.net provides you. A small example:

    You set the second page on the submit button as:

    PostBackUrl="SecondPage.aspx"
    

    On SecondPage.aspx you declare where you can get informations

    <%@ PreviousPageType VirtualPath="~/FirstPage.aspx" %>
    

    and you get them by...

    if (Page.PreviousPage != null)
    {
        if(Page.PreviousPage.IsCrossPagePostBack == true)
        {
            // and get the controls of the previous page as
            var SomeVariable = PreviousPage.DropDownlListId.SelectedValue;
        }
    }
    

    Some reference.
    Cross-Page Posting in ASP.NET Web Pages
    ASP.NET how to access public properties?
    Cross-page postbacks and back again retaining data from source page
    Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?

提交回复
热议问题