HI I have an aspx page ResourceCategories.aspx where in I have registered two user controls:
My problem is I have to access the user control 2)downloadPopUp in 1)ctlCategories on btn click event.
protected void btnArrow_Click(object sender, EventArgs e)
{
//lblMessages.Text = String.Empty;
try
{
var userControl = FindControl("ctlPopUp") as UserControl;
}
catch (Exception ex)
{
}
}
I'm still getting the usercontrol value as null. How it can be accessed? I'm able to access only of I register 2nd user control in first user control but not from the main aspx page.ie; Registering in ResourceCenter.ascx. I dont want to nest user control inside another user control.. is there a way ?
With this code you don't need to use FindControl
, since you have only a single categoryPopup
directly on your page, declared using runat="server"
:
<downloadPopUp:categoryPopup id="ctlPopUp" runat="server"></downloadPopUp:categoryPopup>
Therefore in your code you can use ctlPopup
directly to access the control.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.