How do you pass value of a text box from page1.aspx to
page2.aspx without storing it as a session value?
Answer Posted / 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 |
Post New Answer View All Answers
What's singleton activation mode in .net?
What is the difference between response.write & response.output.write?
Do you know what's the difference between .net and laravel?
Tell us what is json data, and what is one way that .net developers can work with json?
What is Flyout Design Pattern in .NET?
What is garbage collection and how it works ?
What is equivalent for regsvr32 exe in .net ?
Is there built-in support for tracing?
Explain the difference between managed and unmanaged code?
Explain me what is .net web service?
What is UDDI and how to register the web service in it?
Explain about managed heap?
What are Attributes in .NET?
Explain what is the difference between odbc and ado?
Explain different types of html, web and server controls.