繁体   English   中英

在内容页面的嵌套母版页面中读取用户控件属性

[英]Reading User control property inside Nested Master pages in Content page

我在根母版页中有一个用户控件。 内容页面通过嵌套母版页连接到此根母版页

root.master> apps.master> content.aspx

root.master中的用户控件具有一个下拉列表,该下拉列表在更改下拉列表选择时设置属性。

我需要在内容页面中访问此用户控件属性。

任何帮助表示赞赏

用户控件属性

 private string _userCurrentCity = string.Empty;


    public string userCurrentCity
    {

        get { return _userCurrentCity; }

        set { _userCurrentCity = value; }

    }

 protected void ddl_City_SelectedIndexChanged(object sender, EventArgs e)
    {
        string CurrentCity = "";

        CurrentCity = ddl_City.SelectedItem.Text;
        lbl_CurrentCity.Text = CurrentCity;
        HiddenField_CityID.Value = ddl_City.SelectedValue;
        UpdatePanel2.Update();

        userCurrentCity = CurrentCity;//this sets the usercontrol property
    }

在我的内容页面

  UserControl cnt = this.Master.Master.FindControl("Change1") as UserControl;            


  lbl_Result.Text = cnt.userCurrentCity;

这是正确的吗,我在ddl选择的更改事件中设置了userCurrentCity属性。 您的代码看起来合乎逻辑,但无法正常工作。

您需要在后面的代码中添加如下代码:

UserControl cnt = this.Master.FindControl("IDOfTheUserControl") as UserControl

之后:

cnt.Property //to access the wanted property.

编辑: 我不明白,你已经嵌套了母版页。

试试this.Master.Master.FindControl和其他类似的东西。

UserControl cnt = this.Master.Master.FindControl("IDOfTheUserControl") as UserControl

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM