Postback and Cross Page Posting
If(Page.IsPostBack==true)
Ispostback->
When the page is loaded for the first time it is false, when the page is loaded again then it is true.
Example
If (Ispostback) ->
If true then it goes inside that loop
If (! ispostback) ->
If false then it goes inside that loop. We write this line in page load in most of the application.
Cross Page PostBack is which is used to submit one Page(Default.aspx) controls to another page(Default2.aspx) and access Default.aspx control values in Another Page(Default2.aspx)
Example
Cross page posting is submitting the form to a different page. This is usually required when you are creating a multi-page form to collect information from the user on each page. When moving from the source to the target page, the values of controls in the source page can be accessed in the target page.
Design the Form as
Default2.aspx
Default2.aspx.cs
Go to Default3.aspx
Default3.aspx.cs
Difference between Server. Transfer and Cross Page Posting
In ‘Server.Transfer’, the URL doesn't change whereas in cross page posting, the form is submitted to a different page, thereby changing the url.
The Server.Transfer method is a server-based operation whereas cross-page postback is a client-based transfer.
By using Master Page
ContentPlaceHolder pageContent =
(ContentPlaceHolder)
(Page.PreviousPage.Form.FindControl ("Content1"));
TextBox1.Text = pageContent.FindControl("button1");
To avoid casting the control type, you can also access the previous page data(Default2.aspx) by creating public properties that expose the data that you need to access.
In Default2.aspx
public String BTarget
{
get
{
return button1.Text;
}
}
In the ‘Default3.aspx’, access the value of the Button using the exposed property
Label1.Text = PreviousPage.BTarget;
No comments:
Post a Comment
Thank you for visiting my blog