How To: Cross Page Posting

Handshake
Handshake @Image courtesy of pat138241/ FreeDigitalPhotos.net

How To: Cross Page Posting

Welcome to CodeSpread!

What is a POST?

Wikipedia says,The POST request method is designed to request that a web server accept the data enclosed in the request message’s body for storage.It is often used when uploading a file or submitting a completed web form.

Usually, the user clicks a button and the information in the page is posted to the Web server. In ASP.NET, HTTP POST is referred to as Postback. During Postback, the page is posted back to itself. On server, Code processing happens and the page is rendered back with processed values or output.

What is Cross-Page Posting?

Post process works for the same page but in some scenarios, it might be required that the page post  to a different page and not to itself. For example, A multi-page registration form,or a customer order form where user navigates to multiple pages and current page processes the data submitted on the previous page.

This is called cross-page posting.

But we have Transfer method…?

Cross-page posting provides benefits like it is client-based transfer, whereas Server.Transfer method is a server-based operation.

How To?

  • Set the PostBackUrl property of the control which is used to trigger postback, to the new page.
  • To Get Control Values:

if (Page.PreviousPage != null)

{

TextBox txtName = (TextBox)Page.PreviousPage.FindControl("TextBox1");

if (txtName != null)

{

Label1.Text = txtName.Text;

}

}

We use PreviousPage property of Page class to refer the previous page. After that, we just have to call FindControl() method to find the source controls and extract their values.

Note: If it is a Postack operation, PreviousPage property will not be instantiated and inside logic will not get executed. We have taken care of that by providing Null Check.

We have taken care of PostBack Check in the above example.

But How to to determine whether the page was invoked from a cross-page posting or a Server.Transfer operation?

No problem, ASP.Net provides a very useful property called IsCrossPagePostBack.


if(PreviousPage != null)

{

if(PreviousPage.IsCrossPagePostBack == true)

{

//Some Operation;

}

}

This property determines whether the target page is running as the result of a cross-page post or not.

Conclusion

We have inbuilt mechanism in ASP.Net to create multipage forms and read values from cross page posting. It has its own advantages and helpful properties to ease the implementation. Cheers!

Author: hershey

A passion for knowledge drives me to do programming, A passion for programming drives me to create something different, A passion for creation drives me to spread the knowledge.

Share This Post On

0 Comments

  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

More from CodeSpread:

  • Few lines about PreRender eventFew lines about PreRender eventBackground To know PreRender and understand its  importance, we should know the events before it and after it. We start with, Page object including all controls are loaded and the page is ready...
  • Custom error mode in ASP.NET web.configCustom error mode in ASP.NET web.config Dual Roles As a developer, I would love to see the error page that provides details of the error, status code and also the stack information. This information is useful to debug the application ...
  • Agile Encounters UnpredictabilityAgile Encounters UnpredictabilityWhat is Agile? Wikipedia says “Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through...
  • Don’t Mess with App_OfflineDon’t Mess with App_OfflineOne of the most useful features of ASP.NET is the "App_Offline.htm" . It provides a much easy way to make the ASP.NET application offline while we do our modifications on the site. How we do it? ...
  • When ViewState is loaded?When ViewState is loaded?We know asp.net page life cycle and on subsequent request, each stage of life cycle is analyzed to find out, as and when viewstate is available for use.
  • Maintain Page State on Browser’s Back Button ClickMaintain Page State on Browser’s Back Button ClickThis is a very common requirement and a major expectation for a quality user experience. Scenario: User visits a site which heavily uses AJAX. Here, AJAX will not let the user navigate from the p...
  • SQL fry: PIVOT and UNPIVOTSQL fry: PIVOT and UNPIVOTWhat is PIVOT? In our day-to-day SQL server coding, PIVOT and UNPIVOT are not very familiar words but still holds good if we understand them correctly and know when to use it.Web Definition of PIV...
  • ASP.NET : Stick to the ContextASP.NET : Stick to the ContextWhat we are talking about? We are talking about HttpContext Class. It is a part of System.Web namespace/assembly and is usually referred by, [code] System.Object System.Web.HttpContext [...