用户控件在父页面上事件处理
我们想在父页面上获取用户控件中dropdownlist的事件
1.在用户控件Region.ascx中
<asp:DropDownList CssClass="shortSelect required" AutoPostBack="true" ID="ddlCounty" runat="server" OnSelectedIndexChanged="ddlCounty_SelectedIndexChanged"> </asp:DropDownList>
在后台中:
public EventHandler eventSelect; protected void ddlCounty_SelectedIndexChanged(object sender, EventArgs e) { if (this.eventSelect != null) { this.eventSelect(this, e); } }
2.在父页面中:
protected void Page_Load(object sender, EventArgs e) {
llTreeViewMenu.Visible = false; this.SetRegion1.eventSelect += new EventHandler(UserControl_Clicked);
}
private void UserControl_Clicked(object sender, System.EventArgs e) {
llTreeViewMenu.Visible = true;
}
ok 我可以根据dropdownlist下来改变时候根据这个选择的值来在父页面进行左侧菜单的隐藏显示