开发者

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 no开发者_高级运维t working

Finding and accessing elements of a WebUserControl

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

Regards


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜