Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Gauge for SharePoint
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » ASP.NET 2.0/3.5 » Use of PostBackUrl in ASP.NET 2.0

Use of PostBackUrl in ASP.NET 2.0

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.

Author Rank :
Page Views : 45279
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction:

 

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:

 

PostBackUrl="http://www.c-sharpcorner.com".

 

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

 

MyPage.aspx:

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>My Page</title>

</head>

<body>

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

    <div>

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

        <tr>

          <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="http://www.c-sharpcorner.com" Text="Submit" OnClick="Button1_Click" />

          </td>

        </tr>

      </table>

    </div>

  </form>

</body>

</html>

 

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:

 

MyPage.aspx.cs:

 

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {}

    protected void Button1_Click(object sender, EventArgs e)

    {

        if (PreviousPage != null)

        {

            TextBox txtName = (TextBox)

            PreviousPage.FindControl("txtName");

            this.TxtName.Text= txtName.Text;

        }

    }

}

 

Output:  After debug the .cs 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="http://www.c-sharpcorner.com", so the following page will open that mean the page will post to c-sharpcorner.com.

 

 

 

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.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Purushottam Rathore

I am working as a Software Developer and has 4 years of experience on Microsoft Technology and having a Master Degree in Computer Application. I really like to work in the .NET platform. and working with ASP.NET 2.0/3.5, Web Services, WPF, WCF, Silverlight, AJAX, JavaScript, JQuery, Ado.net, MsAccess, SQL Server 2005/2008.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments
This is completely wrong and should be removed. by Vic On March 14, 2011
Sorry but, you're using PreviousPage on the source page (source page IS the previous page), using an onclick that won’t be reached (a side effect of posting to another page), redirecting to an external site (thus losing any info from ‘PreviousPage’) and setting TxtName.Text to FindControl("txtName") when the latter isn't even defined anywhere!
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.