ASP.NET training and interview question: – What is cross page posting?

This is most frequently asked during ASP.NET interview questionsBy 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. Remember this question is fromis a feature in ASP.NET 2.0. In most cases this is the desired behavior, but occasionally 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 does not 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.

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 systematic guide for implementing the cross-page post back using controls that implement the IButtonControl interface.

  • Create a Web Form and insert a Button control on it using the VS .NET designer.
  • Set the button’s PostBackUrl property to the Web Form you want to post back. Forinstance in this case it is “nextpage.aspx”

<asp:Button ID=”Button1″ runat=”server”

PostBackUrl=”~/nextpage.aspx” Text=”Post to nextpage” />

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 Page 2″ onclick=”javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(“Button1”, “,false”,”Page2.aspx”, false, false))”id=”Button1″ />

Also see following ASP.NET Training and interview questionsvideo on Session VS Viewstate difference


Do visit for more important ASP.NET interview questions and answer atwww.questpond.com

The above question is taken from the book .NET interview questions published by BPB publication and written by ShivprasadKoirala.

Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s