Cross-Page Postbacks Made Easy with .NET 2.0
page 1 of 3
Published: 26 Oct 2007
This article provides a brief walk through and explanation of the cross-page post back functionality that has been added back into the .NET Framework.
by Shaun Eutsey
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27508/ 39


New technology is wonderful. I love going into things and looking at the nuts and bolts and figuring out how things work. This has led my wife to many hours of despair as I have tried to "fix" things that were not working too well. One thing was guaranteed, after it has been "fixed," it would be heading to the garbage truck the next week. But I digress. Sometimes new technology forgets things that worked with older versions, leaving common and necessary functions behind in the rush to get things to market.

One of the things that ASP.NET 1.0 and 1.1 forgot from classic ASP was the ability to perform cross-page postbacks. Sure, we could still do a Server.Transfer or a Response.Redirect, but these methods leave a lot to be desired. Security for one is a nightmare; things can get ugly quick if you have malicious end users intent on destruction.

Thankfully, with .NET 2.0, Microsoft has brought back something that I have dearly missed.  Not only have they brought it back, they have made it so much better that it makes my head spin. Even more than that, I have found that not too many people are using them. Most developers I have talked to do not even know that they can use it. They are still using Server.Transfer or Response.Redirect. 

If this is you, my dear reader, there is a light at the end of the tunnel. You have stumbled on a gold nugget that will make your development richer than you can imagine (OK, maybe that last statement is a little presumptuous.)

View Entire Article

User Comments

Title: Good piece   
Name: Vino
Date: 2008-09-26 10:19:14 AM
Really a good piece of article in a simplest way possible. Good Effort. Keep up the good work.
Title: Re: Limitation(s)   
Name: Florin Labou
Date: 2007-11-09 8:16:02 AM
When you need to postback from more pages to Page2.aspx you'll need to define a 'contract' that describes the list of expected transferred values to Page2.aspx.

When Page1.aspx and Page3.aspx need to postback to Page2.aspx you may create a base page:
public abstract class SourceBasePage : System.Web.UI.Page
public abstract Int32 MessageID { get; }
public abstract String Subject { get; }
public abstract String Message { get; }
Page1.aspx and Page3.aspx should inherit from this SourceBasePage. Page2.aspx should describe the previous page type by TypeName:
<%@ PreviousPageType TypeName="MyNamespace.SourceBasePage" %>

So one solution is inheritance.

I hope this will help.

Florin Labou
Title: nice article   
Name: Sandeep
Date: 2007-11-09 6:34:02 AM
Really good information presented in simple to understand manner!
Title: Limitation ?   
Name: Abdul wahab
Date: 2007-11-05 1:53:58 AM
thats a nice article written
my question is : what if my page 2 expect input from two different pages in that case how will previous page will work
Title: Limitations   
Name: Pawan Bansal
Date: 2007-10-31 1:37:03 AM
Hi Shaun!

thanks for writing this article. but the whole concept still has limitations that restricts the use of this concept. You should have a one way channel of the forms to be called like here Page1 is calling Page2. what if the Page2 needs to opened from many other pages as well. Like doing some common functionality from various pages and passi ng the query filter from each page. This will not help in that scenario. Moreover if in any case Page2 calls back Page1 then also it is going to fail.

I think the concept still needs a lot more to be done for a real time useful utility.
Title: Awesome!!   
Name: Nishanth Nair
Date: 2007-10-31 12:51:11 AM
Very good article. Written in plain simple english. Was very useful.
Title: It's Works fine!   
Name: Azad
Date: 2007-10-31 12:22:59 AM
Thanks for your nice article .Its really good .
Title: Very Nice!!   
Name: siva
Date: 2007-10-31 12:08:43 AM
Very Nice Article !!!!!!
Title: Newbie Learning   
Name: Barney3012
Date: 2007-10-29 7:30:04 AM
As a newbie things like this are really useful. I have used the old redirect a few times and as a new person you do not often see ways of doing the basics like moving values from page to page. This is a very useful article.
Thanks for taking the time

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-24 8:40:14 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search