Search code examples
c#asp.netfindcontrol

Finding control on aspx


I have a Promote.aspx page which has a few radcomboboxes; radTerm and radOldYear. Promote.aspx also has a radgrid which is updatable by a WebUserControl, promote.ascx. This Web user control has a few radcomboboxes, radName and radNewyr.

In the promote.ascx.cs, i want to be able to find the comoboxes which are on the promote.aspx. Tried using:

RadComboBox tl = (RadComboBox)this.Page.FindControl("radTerm");

in vain! Someone please help me find the controls on the main page. i am calling them thru the webusercontrol that i load in the radgrid.


Solution

  • First, you have to find the promote.ascx control on the page, so:

    Control promote = (Control)this.Page.FindControl("WhateverYouCalledPromote");
    

    Now that you have found the control, you can search for the control that you want:

    RadComboBox tl = (RadComboBox)promote.FindControl("radTerm");