Cross page posting is used to submit a form to a different page while creating a multi-page form to collect information from the user. You can specify the page you want to post to using the PostBackURL attribute.
In the context of ASP.NET, cross-page posting refers to a technique where the form submission of one web page is directed to another web page for processing. This allows for separation of concerns and can be useful in scenarios where the form submission needs to be handled by a different page than the one containing the form itself.
Here’s how it typically works:
- A form is created on one ASP.NET web page (
Page A
) with itsPostbackUrl
property set to another page (Page B
). - When the form is submitted, the data is posted to
Page B
. Page B
can then access the form data through thePreviousPage
property and perform any necessary processing.
Here’s a brief overview of how to implement cross-page posting in ASP.NET:
On Page A
:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageA.aspx.cs" Inherits="YourNamespace.PageA" %>
<form id="form1" runat="server" PostBackUrl="PageB.aspx">
<!-- Form elements -->
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</form>
On Page B
:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageB.aspx.cs" Inherits="YourNamespace.PageB" %>
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox txtData = (TextBox)PreviousPage.FindControl("txtData");
if (txtData != null)
{
string data = txtData.Text;
// Process the data
}
}
}
In this example, Page B
retrieves data from Page A
by accessing controls from the PreviousPage
property. This allows Page B
to process the form data submitted from Page A
.
So, in an interview setting, your answer would be something like:
“A cross-page posting in ASP.NET is a technique where the form submission of one web page is directed to another web page for processing. It involves setting the PostBackUrl
property of a form on one page to another page. When the form is submitted, the data is posted to the specified page, which can then access the form data through the PreviousPage
property and perform the necessary processing.”