Pass value to next page

I have a login page, after logging in, I create a session variable to store UserName. I used this variable to get the information for this user account from the Account Account, name, etc., And I return the account ID on the page using the label (lblAccountID).

I have a "Add Funds" button to this account, which is redirected to the AddFunds.aspx page

How to transfer an account identifier to the AddFunds.aspx page, which will be used to insert information into the Funds table, which has an account identifier.

I do not want the account identifier to be visible on the AddFunds.aspx page.

+5
source share
6 answers

There are several ways to achieve this. I can briefly explain to you the 4 types that we use in our daily programming life cycle.

Please proceed to the following points.

1 Request string.

FirstForm.aspx.cs

Response.Redirect("SecondForm.aspx?Parameter=" + TextBox1.Text);

SecondForm.aspx.cs

TextBox1.Text = Request. QueryString["Parameter"].ToString();

This is the most reliable way when you pass an integer value type or other short parameters. Make enough progress in this method, if you use any special characters in the value when passing it along the query line, you must encode the value before moving to the next page. So, our code fragment will be something like this:

FirstForm.aspx.cs

Response.Redirect("SecondForm.aspx?Parameter=" + Server.UrlEncode(TextBox1.Text));

SecondForm.aspx.cs

TextBox1.Text = Server.UrlDecode(Request.QueryString["Parameter"].ToString());

2. Passing a value through a context object

Passing a value through a context object is another commonly used method.

FirstForm.aspx.cs

TextBox1.Text = this.Context.Items["Parameter"].ToString();

SecondForm.aspx.cs

this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("SecondForm.aspx", true);

, , Server.Transfer Response.Redirect. Session . Session, Session .

3. PostBack

. :

FirstForm.aspx.cs

private void Page_Load(object sender, System.EventArgs e)
{
buttonSubmit.Attributes.Add("onclick", "return PostPage();");
}

javascript .

SecondForm.aspx.cs

function PostPage()
{
document.Form1.action = "SecondForm.aspx";
document.Form1.method = "POST";
document.Form1.submit();
}
TextBox1.Text = Request.Form["TextBox1"].ToString();

, . , . EnableViewStateMac=false

4. PostBackURL

ASP.NET 2.0 Microsoft , PostBackURL . - , .

FirstForm.aspx.cs

<asp:Button id=buttonPassValue style="Z-INDEX: 102″ runat="server" Text="Button"         PostBackUrl="~/SecondForm.aspx"></asp:Button>

SecondForm.aspx.cs

TextBox1.Text = Request.Form["TextBox1"].ToString();

PostBackUrl , , , . , Request.

PreviousPage Request.

SecondForm.aspx

TextBox textBoxTemp = (TextBox) PreviousPage.FindControl("TextBox1″);
TextBox1.Text = textBoxTemp.Text;

, .

: " - ASP.NET"

+27

:

int AccountIdVar;
Session["AccountID"] = AccountIdVar;

int AccountIdVar = (int)Session["AccountID"];
+1

, , , , , www.foofoofoo.com?Id=23456.

0

, Session Querystring. POST

How to transfer values ​​between pages of a page is worth a look too.

0
source

The article MSDNon Pass Values ​​Between ASP.NET Web Pages is the best place to look.

0
source

To do this, we can also use a global variable, create a module class in which we declare all variables with an open data type, and then assign values. Once a value is assigned, it can be accessed from anywhere.

0
source

All Articles