<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Cross Page Postback
Example in asp.net</title>
</head>
<body>
<form id="form1"
runat="server">
<div>
<table>
<tr>
<td><b>Enter UserName:</b></td>
<td><asp:TextBox ID="txtUserName"
runat="server"/></td>
</tr>
<tr>
<td><b>Enter Location:</b></td>
<td><asp:TextBox ID="txtLocation"
runat="server"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnPostback"
Text="Postback"
runat="server"
PostBackUrl="~/Default2.aspx"
/> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Cross Page Postback
Example in asp.net</title>
</head>
<body>
<form id="form1"
runat="server">
<div>
<b><u>Default2.aspx Page</u></b><br /><br />
<label id="lblName"
runat="server"
/><br
/><br
/>
<label id="lblLocation"
runat="server"
/>
</div>
</form>
</body>
</html>
|
using System;
using
System.Web.UI.WebControls;
|
protected void Page_Load(object
sender, EventArgs e)
{
if (PreviousPage != null
&& PreviousPage.IsCrossPagePostBack)
{
TextBox txtName =
(TextBox)PreviousPage.FindControl("txtUserName");
TextBox
txtLocation = (TextBox)PreviousPage.FindControl("txtLocation");
lblName.InnerText = "Welcome to
Default2.aspx page " + txtName.Text;
lblLocation.InnerText = "Your
Location: " + txtLocation.Text;
}
else
{
Response.Redirect("Default.aspx");
}
}
|
Imports
System.Web.UI.WebControls
Partial Class Default3
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As
Object, e As EventArgs) Handles
Me.Load
If PreviousPage IsNot
Nothing AndAlso
PreviousPage.IsCrossPagePostBack Then
Dim txtName As TextBox = DirectCast(PreviousPage.FindControl("txtUserName"), TextBox)
Dim txtLocation As TextBox = DirectCast(PreviousPage.FindControl("txtLocation"), TextBox)
lblName.InnerText = "Welcome to
Default2.aspx page " & txtName.Text
lblLocation.InnerText = "Your
Location: " & txtLocation.Text
Else
Response.Redirect("Default.aspx")
End If
End Sub
End Class
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|


Subscribe by RSS
Subscribe by Email
6 comments :
it's really nice article
i think this is more easier like,
in default2.aspx, in page_load
assign
string uname,loc;
uname=Request.form["txtUserName"];
loc=Request.form["txtLocation"];
lblName.text=string.format("Welcome to Default2.aspx page {0}
Your Location: {1}",uname,loc)
only 1 label is enough
SIR PLEASE TELL ME LIKE GMAIL SUPPOSE I AM LOGGING IN GMAIL THEN THERE IS ALSO A CROSS PAGE POSTBACK WITH SOME GIF IMAGE WHICH SHOW THE WATING ,SIR IS THIS POSSIBLE WITH THIS CODING/PLEASE ANSWER ME SIR
Valuable example it's a great article thanks for sharing this informative information.. I will visit your blog regularly for some latest post.
Awesome...!
gud