Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
How can i get selected listbox item on the other page,I want when item is selected then automatically page redirect to other page and this value used in other page,

What I have tried:

Here is my try :
C#
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
   {
       Session["MyVar"] = ListBox1.SelectedValue;
       Response.Redirect("home.aspx");
   }

and here is aspx
C#
<asp:ListBox ID="ListBox1" runat="server" Height="202px" Width="262px" 
        style="margin-left: 247px; margin-top: 68px" 
        onselectedindexchanged="ListBox1_SelectedIndexChanged">
        <asp:ListItem></asp:ListItem>
</asp:ListBox>

I know session variable used in next page but problem is page is not redirected,I want when i select item then automatically page redirect to other page.Thanks
Posted
Updated 3-Apr-16 18:16pm
v2

1 solution

Add AutoPostBack="true" to the ListBox control
ASP.NET
<asp:ListBox ID="ListBox1" AutoPostBack="true" runat="server" Height="202px" Width="262px"
      style="margin-left: 247px; margin-top: 68px"
      onselectedindexchanged="ListBox1_SelectedIndexChanged">
 
Share this answer
 
v2
Comments
Hameed Khan 4-Apr-16 4:12am    
Thanks it's working now.
Karthik_Mahalingam 4-Apr-16 4:49am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900