how to pass value from one page to another in asp.net

Posted by Shanky11 under ASP.NET on 7/16/2013 | Points: 10 | Views : 965 | Status : [Member] | Replies : 2
there is a buttn and text box on page 1st
whatever user write in ths texbox
should display in anotehr page label
i am trying this
public String gettext
{
get
{
return TextBox1.Text;
}
}
Server.Transfer("Default2.aspx");


page 2 coding---------------
Label2.Text = PreviousPage.gettext;
but its not working




Responses

Posted by: Satyapriyanayak on: 7/16/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{


protected void Button1_Click(object sender, EventArgs e)
{
Session["uname"] = TextBox1.Text;
Response.Redirect("WebForm1.aspx");

}
}
}




<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["uname"].ToString();
}
}
}


If this post helps you mark it as answer
Thanks

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kamlesh420 on: 7/16/2013 [Member] Starter | Points: 25

Up
0
Down
go with the session or querry string it is very simple and easy to undersand

kamlesh kuamr saini
Sr. devloper (asp.net)
new delhi

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response