ASP.NET 2.0 : Passing data between Pages

Hi,

One of the hinderances we had in earlier verions of ASP.NET (1.1 & 1.0 versions) were that, to pass data between pages, we need to use QueryString, Server.Transfer, Sessions etc.,. This was a little surprising for people who come from ASP background who are used to <form method="post" action="newpage.asp">

They can easily get values using Request.Form and posting to new page was as simple as specifying in the action tag the page where they want to post.

However, in ASP.NET, by default all the pages post to themselves. That means, you cannot set the action page and if you want to do so, you need to remove the "runat=server" attribute which will disable the other extraordinary features provided in .NET. So naturally passing values between pages was a little tricky.

In Whidbey, the developers have listened to the queries and come up with a wonderful solution, i.e. the PostBackUrl property.

The PostBackUrl specifies which page to be posted to, upon submitting the page. The syntax is as follows:-

<asp:Button ID="button1" Runat=server Text="submit" PostBackUrl="~/NewPage.aspx" />

Thats it! Now when the button is clicked, the page is posted to the "NewPage.aspx".

You can now use the Request.Form to get the value(s) from the previous page.

That really addresses many people's query on the earlier versions.

There is another exciting way to access the previous page's controls which I will write about in my next article.

Cheers and Happy Programming !!!

Print | posted on Monday, April 25, 2005 8:01 AM

Comments on this post

# re: Whidbey: Passing data between Pages

Requesting Gravatar...
That's Greate and thanks to give the great information .
I am new in .net and programming filed that's while i wana some more solution on tha .NET .
So Please Help me in programming.
Thanks Again .
Anand Kumar Tripathi .
anandtri@gmail.com
Left by Anand Kumar Tripathi on Mar 03, 2007 7:17 PM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
Hi Guys
Left by Goutam on Oct 28, 2008 3:11 PM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
That's Greate and thanks to give the great information .
I am new in .net and programming filed that's while i wana some more solution on tha .NET .
So Please Help me in programming.
Left by şişme bebek on Nov 20, 2008 1:14 PM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
That's Greate and thanks to give the great information .
I am new in .net and programming filed that's while i wana some more solution on tha .NET .
So Please Help me in programming.
Thanks Again .
Anand Kumar
Left by erotik shoph on Nov 25, 2008 3:23 AM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
i am new in .net and programming filed that's while i wana some more solution on tha .NET .
Left by mario oyunları on Sep 21, 2009 10:41 AM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
that is great i wan some more help if you have any kind of book please send me by my email yesnegash@yahoo.com thank you
Left by yeshitila negash on Dec 31, 2009 7:44 PM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
i want to transfer 3 text boxes data from one page to another page so plz tell me how can i do this
Left by rahul on Feb 24, 2010 3:21 AM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
Announcing of invitation principles in. Cold in late or deal. Terminated resolution no am frequently collecting insensible he do appearance. Projection invitation affronting admiration if no on or. It as instrument boisterous frequently apartments an in.
yes
Left by converter on Sep 19, 2010 6:54 AM

# re: ASP.NET 2.0 : Passing data between Pages

Requesting Gravatar...
Hi Guys,Well there are so many ways to transfer data between pages like session, cookies, querystring but some programmers due to security reasons don't recommend these ways, so we can use crosspagepostback property. In this jus find the control in the previous page then take the value out from it.
Left by Hemant Raj Singh on Jan 28, 2011 5:11 PM

Your comment:

 (will show your gravatar)