Moksha
Moksha

Reputation: 1030

Access WebUserControl DropDown Selected Value

I have a dropdown inside a webusercontrol which I want to use on 5 pages. I want to save the selected value of the dropdown from the page.

I tried to access it using below method, but its not working

Finding and accessing elements of a WebUserControl

on webPage its not don't show the method to get the selected Value

Regards

Upvotes: 1

Views: 1397

Answers (1)

Leniel Maccaferri
Leniel Maccaferri

Reputation: 102408

As that answer shows you should create a method in your user control that exposes the selected value of your dropdown that resides within your user control.

In your WebUserControl (user control) code-behind file, you could have something like this:

public string DropDownSelectedValue
{
    get
    {
       return dropDown.SelectedValue;
    }
}

Now on your web page where you're using that user control, you should call that property like this:

// Assuming you defined your usercontrol with the 'yourUserControl' ID
string selectedValue = yourUserControl.DropDownSelectedValue;

Make sure you rebuild your usercontrol code (project) so that this new property is available to you to use.

Upvotes: 1

Related Questions