More in this section

Forums / Bugs & Issues / Issue in ContentMetaFields

Issue in ContentMetaFields

5 posts, 1 answered
  1. Nimit
    Nimit avatar
    90 posts
    27 Mar 2009
    10 Aug 2009
    Link to this post
    Can anybody help me in Showing how I can access a control(Textbox,etc.) in Code bebind which is defined in



    sfGCn:ContentMetaFields ID="editMetaFields" runat="server">
    in insert or edit in Custom generic module.

    For example:



    <sfGCn:ContentMetaFields ID="editMetaFields" runat="server">






    <fieldset class="set">



    <div class="setIn">






                <telerik:RadDateTimePicker id="NotificationDate" runat="server"></telerik:RadDateTimePicker>






















    Now in the above example How will I find the control with name "NotificationDate" in code behind.

    Please reply soon,
    Nimit Verma.


  2. Georgi
    Georgi avatar
    3583 posts
    28 Oct 2016
    12 Aug 2009
    Link to this post
    Hi Nimit,

    Since the field is in a container of another control, you do not have an access to it directly. Therefore you can implement a recursive function for searching the control:
    private Control FindControlRecursive(Control root, string id)     
            if (root.ID == id)    
                return root;      
            foreach (Control c in root.Controls)      
                Control t = FindControlRecursive(c, id);      
                if (t != null)    
                    return t;     
            return null;      

    and use it:
    var TextBox = FindControlRecursive(ContentMetaFields, "controlID") as TextBox; 

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. bemara57
    bemara57 avatar
    135 posts
    27 Mar 2008
    17 Feb 2010
    Link to this post
    There is also this if you are working within a view:
    (RadDateTimePicker)base.MetaFields.GetControl("Event_Start", true);

    I wish there was a generic counterpart though like this:
    base.MetaFields.GetControl<RadDateTimePicker>("Event_Start", true);
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    17 Feb 2010
    Link to this post
    Hi Nimit,

    This should also work if you want to access the control from the code behind.

    TextBox tb= cMetaFields .Controls[0].FindControl("Somefield") as TextBox;

    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Min
    Min avatar
    10 posts
    21 Dec 2010
    18 Jan 2011
    Link to this post
    Thank a lot for that function, Georgi!
Register for webinar
5 posts, 1 answered