inicio mail me! sindicaci;ón

ASP.NET crosses a page to send value skill summary

Send the means of the value about the page, caused a lot of discuss. Look a lot of people pay close attention to this, I did some of summary with respect to my individual viewpoint, hope to be helped somewhat to everybody.

1. Use QueryString is variable

QueryString is a kind of very simple way that pass a cost, he can indicate deferent value the address column in the browser is medium. If be to deliver one or more security to ask not tall or it is a structure when simple numerical value, can use this method. But to passing the word of array or object, cannot use this method. An example is below:

The C# code of A.aspx

Private Void Button1_Click(object Sender, system.EventArgs E)
{String S_url;S_url = “b.aspx? Name=” Label1.Text;
Response.Redirect(s_url);
}

Code of the C# in B.aspxPrivate Void Page_Load(object Sender, eventArgs E)
{
Label2.Text = Request.QueryString[”name” ];
}

2. Use Application object is variable

The action limits of Application object is whole overall situation, have an user to place that is to say effective. Its commonly used method uses Lock and UnLock.

The C# code of A.aspx

Private Void Button1_Click(object Sender, system.EventArgs E)
{
Application[”name” ] = Label1.Text;
Server.Transfer(”b.aspx” );
}

Code of the C# in B.aspx

Private Void Page_Load(object Sender, eventArgs E)
{String Name;
Application.Lock();Name = Application[”name” ].ToString();
Application.UnLock();
}

3. Use Session is variable

Most propbably is everybody this for certain the commonnest use in using, its operation and Application are similar, action at user individual, so, what the memory of excessive can bring about server memory resource is extinct.

The C# code of A.aspx

Private Void Button1_Click(object Sender, system.EventArgs E)
{
Session[”name” ] = Label.Text;
}

Code of the C# in B.aspx

Private Void Page_Load(object Sender, eventArgs E)
{String Name;Name = Session[”name” ].ToString();
}

4. Use Cookie object is variable

This also is the method that big the daily life of a family uses, like Session, its are assorted of to each user character, but the distinction that has an essence, namely Cookie is to deposit what carry in the client, and Session is to deposit what carry in the server. And the use of Cookie should cooperate Request of object of the buy inside ASP.NET to use.

The C# code of A.aspx

Private Void Button1_Click(object Sender, system.EventArgs E)
{
HttpCookie Cookie_name = New HttpCookie(”name” );Cookie_name.Value = Label1.Text;
Reponse.AppendCookie(cookie_name);
Server.Transfer(”b.aspx” );
}

Code of the C# in B.aspx

Private Void Page_Load(object Sender, eventArgs E)
{String Name;Name = Request.Cookie[”name” ].Value.ToString();
}

5. Use Server.Transfer method

This ability can say is elephant the method that object development uses, its use Server.Transfer method to conduct technological process in another page from current page, of a page respondent flow, so this method is object of complete face elephant, concise and effective.

The C# code of A.aspx

Public String Name
{Get{Return Label1.Text;}
}Private Void Button1_Click(object Sender, system.EventArgs E)
{
Server.Transfer(”b.aspx” );
}

Code of the C# in B.aspxPrivate Void Page_Load(object Sender, eventArgs E)
{A NewWeb; / / body of example A windowNewWeb = (source)Context.Handler;String Name;Name = NewWeb.Name;
}

Bookmark:Digg Del.icio.us Reddit

Leave a Comment