.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Cross page posting in .Net

Posted By:Asha.MP       Posted Date: November 11, 2010    Points: 50    Category: ASP.NET    URL: http://www.dotnetspark.com  

Cross page posting is used to pass the values from one page to other page.
 

Consider Page1.aspx, this is the body part of the aspx page.

This page consist of one label, one textbox and button.

Page1.aspx

<body>

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

<div>

<asp:Label ID="LblPageName" runat="server" Text="This is Page1">asp:Label>

<br />

<asp:Label ID="LblName" runat="server" Text="Name">asp:Label>

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

<asp:Button ID="BtnOk" runat="server" Text="OK" PostBackUrl="~/Page2.aspx"/>

div>

form>

body>

In the codebehind of the page1.aspx, below is written

Page1.aspx.vb

Public Partial Class Page1

Inherits System.Web.UI.Page

Public ReadOnly Property _Name() As String

Get

Return Me.TxtName.Text

End Get

End Property

Private Sub Page1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim prev As New Page2

prev = TryCast(PreviousPage, Page2)

If prev IsNot Nothing Then

Me.TxtName.Text = prev._updatedName()

Me.LblName.Text = "Updated Name"

End If

Dim ip As String = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString

End Sub

End Class

In this codebehind Property _Name() returns the name from this page to page2(PostBackUrl="~/Page2.aspx"/ in the aspx page)

Page2.aspx 

<body>

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

<div>

<asp:Label ID="LblPageName" runat="server" Text="This is Page2">asp:Label>

<br />

<asp:Label ID="LblName" runat="server" Text="Your Name is">asp:Label>

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

<asp:Button ID="BtnChange" runat="server" Text="Change" PostBackUrl="~/Page1.aspx" />

div>

form>

body>

page2.aspx.vb

Public Partial Class Page2

Inherits System.Web.UI.Page

Public ReadOnly Property _updatedName()

Get

Return Me.TxtName.Text

End Get

End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim prev As New Page1

prev = TryCast(PreviousPage, Page1)

If prev IsNot Nothing Then

Me.TxtName.Text = prev._Name()

End If

End Sub

End Class

 


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend