Page - 1
<%@ 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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Fullname:
<asp:TextBox ID="txtFullname" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Cross Page"
PostBackUrl="~/Default2.aspx"/>
</div>
</form>
</body>
</html>
Page - 2
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
<%@ 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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Fullname:
<asp:TextBox ID="txtFullname" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Cross Page"
PostBackUrl="~/Default2.aspx"/>
</div>
</form>
</body>
</html>
Page - 2
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Page - 2 .CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
TextBox txt = (TextBox)PreviousPage.FindControl("txtFullname");
Label1.Text = txt.Text;
}
}
}
Cross page posting with Master page - ASP.NET
if (Page.PreviousPage != null)
{
var cp = PreviousPage.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
TextBox txt1 = cp.FindControl("txtaddresse") as TextBox;
//TextBox txt = (TextBox)PreviousPage.FindControl("ContentPlaceHolder1_txtaddresse");
if (txt1.Text != null)
{
string s = txt1.Text;
}
}
No comments:
Post a Comment