Cross Page Posting in ASP.NET using VB.NET

In this article we demonstrate on what is Cross page Posting and how you can do Cross Page Posting.
  • 3253

ASP.NET by default Submits the Form to the same page. Cross Page Posting is submitting the form on different page. this is actually needed when you are creating a multipage form to collect information of the user on each page. When moving from the source to the Target page, the values of control in the source page can be accessed in the target page. Cross Page Posting feature allows a page to Cross Post to another page which in turn allows you to access all data in Posted Source Page.
To use Cross Page Posting you have to use the PostBackURL attribute to specify the Page you want to post to. Here I am discussing an example in which I am describing the Cross Page Posting or PostBack in ASP.NET using VB.NET. I have taken two TextBoxes and one Button control, Button click will Post Back to another page and their you will retrieve and show values of both TextBoxes.

Steps for implementation:-

  • Simply open a ASP.NET web application. 
  • Add two TextBoxes, one Button on Default.aspx or write code to add controls.

    <%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
        CodeBehind="Default.aspx.vb" Inherits="WebApplication7._Default" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
            First Name: <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
            Last Name: <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button"
            PostBackUrl="~/Default2.aspx" />

  • The design mode of Default.aspx will look like below.

  • Right-click on design page select view code and write below code.

    Public ReadOnly Property pbTxtFirstName() As TextBox
                Return txtFirstName
            End Get
        End Property
        Public ReadOnly Property pbTxtLastName() As TextBox
                Return txtLastName
            End Get
  • Right-click on Project node and add select New Item. 
  • Select new Web Form and named it to Default2.aspx. 
  • Write the below code on Default2.aspx.

    <%@ PreviousPageType VirtualPath="~/Default.aspx" %>
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default2.aspx.vb" Inherits="WebApplication7.Default2" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  • Right-click on design page of Default2.aspx and select view code and write below code.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If PreviousPage IsNot Nothing AndAlso PreviousPage.IsCrossPagePostBack Then
                Label1.Text = ("Welcome " & PreviousPage.pbTxtFirstName.Text & " ") + PreviousPage.pbTxtLastName.Text
            End If
        End Sub





More Articles

© 2020 DotNetHeaven. All rights reserved.