You are here:

C#/passing values from a usercontrol to another page

Advertisement


Question
hello,
i have created a user control which has 2 dropdownlists .
on clickig the submit button i want to pass the values of the dropdownlists to another page but when i do this i always seem to pass the values of the default options selected in the 2 dropdownlists.
the code is below;

String strURL;
strURL="search_details.aspx?location=" + ddlLocation.SelectedItem.Value + "&state=" + ddlTypeDesc.SelectedItem.Value;
Response.Redirect(strURL);

Any assistance would be appreciated..
thx


Answer
Hi

It's important to know which events are fired when a user changes the dropdownlist.

First, in the Page_Load, you should check for a postback. If it's a postback, then don't bind data to the dropdownlist. This will prevent the user input to be overwritten.

After that, create an event handler for the Drop down list changed, In this event, you can get the selected index in your dropdownlist.

Happy Programming!!

-Srini

C#

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder

©2012 About.com, a part of The New York Times Company. All rights reserved.