【问题标题】:Access WebUserControl DropDown Selected Value访问 WebUserControl DropDown 选定值
【发布时间】:2010-09-05 02:43:10
【问题描述】:

我想在 5 个页面上使用的 webusercontrol 中有一个下拉列表。我想从页面保存下拉列表的选定值。

我尝试使用以下方法访问它,但它不起作用

Finding and accessing elements of a WebUserControl

在网页上它不会不显示获取所选值的方法

问候

【问题讨论】:

    标签: c# asp.net user-controls selectedvalue


    【解决方案1】:

    正如该答案所示,您应该在用户控件中创建一个方法,该方法公开驻留在用户控件中的下拉列表的选定值。

    在您的 WebUserControl(用户控件)代码隐藏文件中,您可以有如下内容:

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

    现在在您使用该用户控件的网页上,您应该像这样调用该属性:

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

    确保您重建您的用户控件代码(项目),以便您可以使用这个新属性。

    【讨论】:

      猜你喜欢
      • 2018-08-10
      • 2015-05-22
      • 2018-03-20
      • 2012-01-01
      • 1970-01-01
      • 2016-08-19
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      相关资源
      最近更新 更多