How do you pass value of a text box from page1.aspx to
page2.aspx without storing it as a session value?

Answers were Sorted based on User's Feedback



How do you pass value of a text box from page1.aspx to page2.aspx without storing it as a session v..

Answer / badrinath

using querystring

Is This Answer Correct ?    13 Yes 0 No

How do you pass value of a text box from page1.aspx to page2.aspx without storing it as a session v..

Answer / rok_here

Through Requested.querystring we can send the value from
one page to another Page

Is This Answer Correct ?    4 Yes 0 No

How do you pass value of a text box from page1.aspx to page2.aspx without storing it as a session v..

Answer / rishiraj r

We can also use cross post back property ofASP.NET 2.0

eg:

1. Specify the ListBox as

<asp:ListBox ID="ListBox1" runat="server" >
<asp:ListItem Value="1" Text="1st Option" />
<asp:ListItem Value="2" Text="2nd Option" />
<asp:ListItem Value="3" Text="3rd Option" />
</asp:ListBox>

2. Add this code in the default.aspx(.cs)

public ListBox TheListBox
{
get
{
return ListBox1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//Generate the cross-page postback script
PostBackOptions options = new PostBackOptions
(ListBox1);
//This will trigger correct script generation
options.ActionUrl = "secondPage.aspx";

//Add it to onchange attribute if the ListBox
string s =
Page.ClientScript.GetPostBackEventReference(options);
ListBox1.Attributes["onchange"]=s;

}

3. Then on secondPage.aspx

3.1 In aspx

<%@ PreviousPageType VirtualPath="~/Default.aspx" %>

3.2 in Page_Load of the secondPage.aspx(.cs)

protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null &&
PreviousPage.IsCrossPagePostBack)
{
Response.Write("You selected " +
PreviousPage.TheListBox.SelectedValue );
}
}

Is This Answer Correct ?    3 Yes 1 No

How do you pass value of a text box from page1.aspx to page2.aspx without storing it as a session v..

Answer / arif khan

Create Default.aspx

this is my Default.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Welcome to Default page1</h1>
<asp:TextBox ID="txt1" runat="server" />
<asp:Button ID="btn" runat="server" Text="Submit"
OnClick="Transfer_Click" />
</div>
</form>
</body>
</html>

Code file
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 Transfer_Click(object sender, EventArgs
e)
{
Server.Transfer("~/Default2.aspx");
}
}


create Default2.aspx

<%@ 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">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Welcome to Default page 2</h1>
<asp:Label ID="lblshow" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

code file

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox txt = (TextBox)Page.PreviousPage.FindControl
("txt1");
lblshow.Text = txt.Text;
}
}

Is This Answer Correct ?    3 Yes 1 No

How do you pass value of a text box from page1.aspx to page2.aspx without storing it as a session v..

Answer / kinjal

in first page write

textbox1.text="k";
string str=textbox1.text.trim();
respons.redirect("page2.aspx?id="+str);

Is This Answer Correct ?    2 Yes 2 No

How do you pass value of a text box from page1.aspx to page2.aspx without storing it as a session v..

Answer / mercy

cookies provide to store information in web applications.
you can add cookies like
Response.Cookies("userName").Value = "mercy"

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Dot Net General Interview Questions

How do you view the methods and members of a dll?

0 Answers  


What is the advantage of .net?

0 Answers  


Will my .net app run on 64-bit windows?

0 Answers  


Explain Different kinds of methods?

0 Answers   Wipro,


What are an object and a class?

0 Answers  






What is the difference between odbc and ado?

0 Answers  


What is Delegate? Have ever used Delegates in your project.

1 Answers   Deloitte,


1 mor thing guyz....can i go for C# directly without C++ /JAVA knowledge for dot net ..???

3 Answers  


How ASP .NET different from ASP?

4 Answers  


what are the controls used to upload a file from client to server?

4 Answers  


Explain the difference between vb and vb.net?

0 Answers  


Explain the code behind wors and contrast that using the inline style.

0 Answers  


Categories