Several methods for passing parameters between asp.net pages-practical tips

Source: Internet
Author: User

The first method:
Pass through URL link address
Send.aspx:

Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
Request.redirect ("Default2.aspx?username=honge");
}

Receive.aspx:
Copy Code code as follows:

String username = request.querystring["username"] so that the parameter values can be obtained.


The second method:
Send.aspx
Copy Code code as follows:

<form id= "Form1" runat= "Server" action= "receive.aspx" method=post>
<div>
<asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "button"/>
<asp:textbox id= "username" runat= "server" ></asp:TextBox>
</div>
</form>

Receive.aspx
Copy Code code as follows:

String username = ruquest.form["Receive"];


The third method:
Send.aspx:
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
session["username"] = "Honge";
Request.redirect ("default2.aspx");
}

\receive.aspx:
Copy Code code as follows:

String username = session["username"] so that the parameter values can be obtained.

The Fourth method:
Send.aspx:
Copy Code code as follows:

protected void Button1_Click (object sender, EventArgs e)
{
application["username"] = "Honge";
Request.redirect ("default2.aspx");
}

Receive.aspx:
Copy Code code as follows:

String username = application["username"] so that the parameter values can be obtained.

The Fifth method:
Send.aspx:
Copy Code code as follows:

public string Name
{
get {
return "Honge";
}
}
protected void Button1_Click (object sender, EventArgs e)
{
Server.Transfer ("default2.aspx");
}

Receive.aspx:
Copy Code code as follows:

Send d = context.handler as send;
if (d!= null)
{
Response.Write (D.name) so that the parameter values can be obtained.
}

If you can also use this in asp.net 2.0:

Copy Code code as follows:

PreviousPage d = Context.Handler as previouspage;
if (d!= null)
{
Response.Write (D.name) so that the parameter values can be obtained.
}

You can also use this:
Send.aspx:
Copy Code code as follows:

<asp:button id= "btnsubmit" runat= "Server" postbackurl= "~/reveive.aspx" text= "Submit"/>

Receive.aspx:
Copy Code code as follows:

<%@ previouspagetype virtualpath= "~/default.aspx"%>
String name = Previouspage.name, so you can get parameter values.


add: In data-bound controls such as DataList or Repeater controls
<a href= "Article.aspx? id=<% #DataBinder. Eval (Container.DataItem, "article_id")%> "target=" _blank ">//" go to the link page and Id,id as a field in the database;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.