Passing Variables to a new page, when clicking sub

2019-03-04 15:03发布

问题:

I have a page with 2 dropdrownlists & a submit button. I would like to pass the values(variables) of the dropdownlists to another page when I click submit.

Any thoughts or suggestions as to accomplish this. I have done something similar to this using asp:HyperLinkField, but I this does not work in my current scenario.

回答1:

You need to place a declaration on the second page where data come from.

So you have:

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)
    {
        GetTheClass = PreviousPage.CustomDataClass;
        // or you find your control, and get your data
    }
}

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



回答2:

What about putting them in session and accessing them from session on another page?



回答3:

cant u use this:

PreviousPage.VAR1 = cboBox1.Text
PreviousPage.VAR2 = cboBox2.Text 

with PreviousPage being the name of your other page??