Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Serial Number in SSRS Articles
Get Started Developing for Android Apps with Eclipse Articles
How to Print a Crystal Report direct to printer Articles
Razor View Engine Interview Questions Answers Interview Questions
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
SPIRE PDF Library Articles
Infosys Interview Questions Interview Questions
Html5 interview questions and answers Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
SharePoint 2010 interview Questions Answers Interview Questions
Submit Articles | More Articles..

cross page posting in ASP.Net

Posted By: rakesh On:12/30/2010 12:21:31 AM in:Interview Questions Category:ASP.NET Hits:5114
In This Article I am explining what is cross page posting in asp.net and how its work

Introduction

By default, button controls in ASP.NET pages post back to the same page that contains
the button, where you can write an event handler for the post. In most cases this is the
desired behavior, but occasionaly you will also want to be able to post to another page in
your application. The Server.Transfer method can be used to move between pages, however
the URL doesn't change. Instead, the cross page posting feature in ASP.NET 2.0 allows
you to fire a normal post back to a different page in the application. In the target page,
you can then access the values of server controls in the source page that initiated the post
back.

Implementation

To use cross page posting, you can set the PostBackUrl property of a Button, LinkButton or ImageButton control, which specifies the target page. In the target page, you can then access the PreviousPage property to retrieve values from the source page. By default, the PreviousPage property is of type Page, so you must access controls using the FindControl method. You can also enable strongly-typed access to the source page by setting the @PreviousPageType directive in the target page to the virtual path or Type name of the source page.
Here is a step-by-step guide for implementing the cross-page post back using controls
that implement the IButtonControl interface.

1 Create a Web Form and insert a Button control on it using the VS .NET designer.

2 Set the button's PostBackUrl property to the Web Form you want to post back. For
instance in this case it is "default.aspx"

Example of Cross page posting

<asp:Button ID="Button1" runat="server"
PostBackUrl="~/default.aspx" Text="Post to Home Page" />


When the PostBackUrl property of the IButtonControl is set, the ASP.NET framework
binds the corresponding HTML element to new JavaScript function named
WebForm_DoPostBackWithOptions. The corresponding HTML rendered by the ASP.NET
2.0 will look like this:


<input type="submit" name="Button1" value="Post to Home page"
onclick="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("Button1", ",false”,"default.aspx", false, false))"
id="Button1" />
comments powered by Disqus
User Profile
Rakesh Sinha
Sr. Technical Lead
New Delhi , India
Email :You must Log In to access the contact details.
Latest Post from :rakesh
Hacked By 4xroix
View: 14 | Submitted on: 5/28/2019 9:07:35 PM
Which party you want to vote in Loksabha elections 2019?
View: 758 | Submitted on: 10/12/2018 5:59:06 PM
Response.Redirect vs Server.Transfer
View: 502 | Submitted on: 12/27/2015 2:26:38 PM
The test form is only available for requests from the local machine.
View: 736 | Submitted on: 11/3/2015 9:54:36 PM
Difference between web service WCF and Web API
View: 7862 | Submitted on: 10/28/2015 9:23:51 PM
Submit Articles | All Post of This User..


Advertise About Us Private Policy Terms of use
All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher