An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

ASP.NET 2.0 : Passing data between Pages

Monday, April 25, 2005 8:01 AM
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 !!!

Feedback

# re: Whidbey: Passing data between Pages

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 3/3/2007 7:17 PM | Anand Kumar Tripathi

Post a comment





 

Please add 2 and 2 and type the answer here: