Use of PostBackUrl in ASP.NET 2.0 using VB.NET

In this article you can understand how the aspx page is PostBack to another aspx Page. ASP.NET 2.0 inludes the button's property to perform this task very simple.
  • 3257



In ASP.NET 1.1 a page can only PostBack to itself, it is a common technique to post the page to another page. In ASP.NET 2.0 ASPX page can post to different ASPX page by using the button's PostBackUrl property. Where ASPX is the extension of ASP.NET web application.


We can see the button's property in the following figure.





Figure 1: Button's PostBackUrl property.


Steps for implementing the cross page PostBack using controls in ASP.NET 2.0:


Step 1: Open the new website in Microsoft Visual studio 2005.


Step 2: Drop a button control on the form and you can also drag other controls according the need of application.


Step 3: Set the PostBackUrl property of the button where you want to PostBack.


For Example: Let us suppose we want to PostBack to another page from "My Page" then we have to pass the PostBackUrl as follows:




Now you can see the source code and also set the PostBackUrl of that page where you want to post the page.




<%@ Page Language="VB" AutoEventWireup="true"  CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >

<head runat="server">

    <title>My Page</title>



  <form id="form1" runat="server">


      <table cellpadding="0" cellspacing="0" border="2" height="50px" style="width: 33%">


          <td align="center" valign="top" style="padding-top:20px;">

            <asp:TextBox ID="TxtName" runat="server"></asp:TextBox><br/><br/>

            <asp:Button ID="BtnSubmit" runat="server" PostBackUrl="" Text="Submit" OnClick="Button1_Click" />









Design view of the above source code:


Figure 2: My first page.


When you post to another page in ASP.NET 2.0, you can reach out to the values in the page using the following methods:






Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls


Partial Public Class _Default
    Inherits System.Web.UI.Page
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If Not PreviousPage Is Nothing Then
            TextBox(txtName = (TextBox))
             Me.TxtName.Text = txtName.Text
        End If
    End Sub
 End Class


Output:  After debug the .vb file you will get the output as:





Figure 3: My Page is display.


After that click on Submit button "My Page" will PostBack to another page. Here we have set the PostBackUrl="", so the following page will open that mean the page will post to





Figure 4: New page is open.


PreviousPage property holds the posted page. We check if it is null and use the FindControl() method to reach our control.


More Articles

© 2020 DotNetHeaven. All rights reserved.