ASP.NET - Referencing a control inside of a user control
ASP.NET Mini Tutorial - Referencing a control inside of a user control
Let's say you have a usercontrol that contains a dropdown list of states that you use across many pages. In the codebehind of the page, you will likely need to reference that dropdown list, but it's nested inside a usercontrol, so you must use the FindControl method to access it.
Example:
First, create a new object called ddlState and make it a dropdownlist
Dim ddlState As DropDownList = StatesDropDown1.FindControl("ddlState")
Now you can reference it just like it was a control on the page:
txtExample.text = ddlState.SelectedValue
Let's say you have a usercontrol that contains a dropdown list of states that you use across many pages. In the codebehind of the page, you will likely need to reference that dropdown list, but it's nested inside a usercontrol, so you must use the FindControl method to access it.
Example:
First, create a new object called ddlState and make it a dropdownlist
Dim ddlState As DropDownList = StatesDropDown1.FindControl("ddlState")
Now you can reference it just like it was a control on the page:
txtExample.text = ddlState.SelectedValue
Comments
Post a Comment