+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Setting value of field on Custom Module

Setting value of field on Custom Module

5 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    17 Sep 2010
    Link to this post
    Hello,

    I've got a custom module which has a asp label on it. When an item is being edited from within the module, I need to set the content of the label, however I cannot get hold of the label no matter what method i try. I've tried:

    protected override Telerik.Cms.Engine.IContent SetContentForm(Telerik.Cms.Engine.IContent cnt) {
     
        Label oLogoLabel = FindControl("lblLogoName") as Label;
        if (oLogoLabel is Label) {
     
            Context.Response.Write("Exists");
     
            ((Label)oLogoLabel).Text = Phoenix.Utilities.GetContentItem(cnt.GetMetaData("Logo").ToString()).ID.ToString();
     
        } else {
     
            Context.Response.Write("Does not exist");
            Context.Response.Write(oLabel == null);
     
        }
     
        return base.SetContentForm(cnt);
         
    }
     
    protected override void InitializeControls(System.Web.UI.Control viewContainer) {
     
         
     
        Label oLogoLabel = viewContainer.FindControl("lblLogoName") as Label;
        if (oLogoLabel is Label) {
     
            Context.Response.Write("Exists");
     
            Guid strContentID = new Guid(this.Page.Request.QueryString[this.ParameterKey]);
            Telerik.Cms.Engine.IContent oContent = this.Host.Manager.GetContent(strContentID);
     
            ((Label)oLogoLabel).Text = Phoenix.Utilities.GetContentItem(oContent.GetMetaData("Logo").ToString()).ID.ToString();
     
        } else {
     
            Context.Response.Write("Does not exist");
            Context.Response.Write(oLabel == null);
     
        }
     
     
        base.InitializeControls(viewContainer);
         
    }
     
    protected override void CreateChildControls() {
         
     
        Label oLogoLabel = FindControl("lblLogoName") as Label;
        if (oLogoLabel is Label) {
     
            Context.Response.Write("Exists");
     
            Guid strContentID = new Guid(this.Page.Request.QueryString[this.ParameterKey]);
            Telerik.Cms.Engine.IContent oContent = this.Host.Manager.GetContent(strContentID);
     
            ((Label)oLogoLabel).Text = Phoenix.Utilities.GetContentItem(oContent.GetMetaData("Logo").ToString()).ID.ToString();
     
        } else {
     
            Context.Response.Write("Does not exist");
            Context.Response.Write(oLabel == null);
     
     
        }
     
        base.CreateChildControls();
     
    }
     
    protected virtual Label oLabel {
     
        get {
            return base.Container.GetControl<Label>("lblLogoName", false);
        }
     
    }

    Shouldn't one of these mthods give me access to the controls on the form?

    Thanks in advance
    higgsy
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Sep 2010
    Link to this post
    Hi Alastair,

    Thank you for using our services.

    Could you please let us know where in the template you have the label added? Using base.Container.GetControl<> should be sufficient to get a control in the markup of the control template.


    Best wishes,
    Radoslav Georgiev
    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
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    17 Sep 2010
    Link to this post
    Hi Radoslav,

    Its within the metafields area, although it is not a metafield. Does that make sense?

    01.<sf:ContentMetaFields id="MetaFields" runat="server">
    02.            <ItemTemplate>
    03.                <fieldset class="set">
    04.                    <ol class="setIn">
    05.                        <li class="catSel clearfix">
    06.                            <asp:Label AssociatedControlID="Category" runat="server">
    07.                                <asp:Literal runat="server" Text="<%$Resources:CategoryFieldLabel %>"></asp:Literal>
    08.                            </asp:Label>
    09.                            <sf:ContentCategoriesField ID="Category" runat="server" />
    10.                        </li>
    11.                    </ol>
    12.                </fieldset>
    13.                <div class="bottom"><div><!-- --></div></div>
    14.                 <h3>
    15.                    <asp:Literal runat="server" Text="<%$Resources:Tags %>"></asp:Literal></h3>
    16.                <fieldset class="set">
    17.                    <ol class="setIn">
    18.                        <li class="tags">
    19.                            <sf:ContentTagEditor ID="tagsControl" runat="server" />
    20.                        </li>
    21.                    </ol>
    22.                </fieldset>
    23.                <div class="bottom"><div><!-- --></div></div>
    24.                <h3><asp:Literal runat="server" Text="<%$Resources:AdditionalInfoLabel %>"></asp:Literal></h3>
    25.                <fieldset class="set">
    26.                    <div class="setIn">                   
    27.                    <p class="example"><asp:Literal runat="server" Text="<%$Resources:AdditionalInfoNote %>"></asp:Literal></p>
    28.                    <ol>
    29.                        <li>
    30.                            <asp:Label AssociatedControlID="Client" runat="server">
    31.                                <asp:Literal runat="server" Text="<%$Resources:ClientFieldLabel %>"></asp:Literal>
    32.                            </asp:Label>
    33.                            <asp:TextBox ID="Client" runat="server"></asp:TextBox>
    34.                            <asp:RequiredFieldValidator runat="server" ControlToValidate="Client" Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True">
    35.                                <strong>
    36.                                    <asp:Literal runat="server" Text="<%$Resources:ClientFieldEmpty %>"></asp:Literal>
    37.                                </strong>
    38.                            </asp:RequiredFieldValidator>
    39.                        </li>
    40.                        <li class="clearfix">
    41.                            <asp:Label AssociatedControlID="Logo" runat="server">
    42.                                <asp:Literal runat="server" Text="<%$Resources:LogoFieldLabel %>"></asp:Literal>
    43.                            </asp:Label>
    44.                            <asp:TextBox ID="Logo" runat="server" style="display: none;"></asp:TextBox>
    45.                            <asp:Label ID="lblLogoName" runat="server" style="width: 365px; float: left; margin: 5px 5px auto auto;" Text="None selected" />
    46.                            <asp:HiddenField ID="hdnNoLogoMsg" runat="server" Value="None selected" />
    47.                            <div style="float: left; margin: 5px 5px auto auto;">
    48.                                <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" associatedcontrols="Logo,lblLogoName" runat="server" ButtonText="Choose a logo" /> | <span><a href="#" id="lnkRemoveLogo">Remove logo</a></span>
    49.                            </div>
    50.                            <asp:RequiredFieldValidator runat="server" ControlToValidate="Logo" Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True">
    51.                                <strong>
    52.                                    <asp:Literal runat="server" Text="<%$Resources:LogoFieldEmpty %>"></asp:Literal>
    53.                                </strong>
    54.                            </asp:RequiredFieldValidator>
    55.                        </li>
    56.                        <li>
    57.                            <asp:Label AssociatedControlID="Summary" runat="server">
    58.                                <asp:Literal runat="server" Text="<%$Resources:SummaryFieldLabel %>"></asp:Literal>
    59.                            </asp:Label>
    60.                            <asp:TextBox ID="Summary" runat="server" textmode="MultiLine"></asp:TextBox>
    61.                            <asp:RequiredFieldValidator runat="server" ControlToValidate="Summary" Display="Dynamic" EnableViewState="False" CssClass="validMessage" SetFocusOnError="True">
    62.                                <strong>
    63.                                    <asp:Literal runat="server" Text="<%$Resources:SummaryFieldEmpty %>"></asp:Literal>
    64.                                </strong>
    65.                            </asp:RequiredFieldValidator>
    66.                        </li>
    67.                        <li class="clearfix">
    68.                            <asp:Label AssociatedControlID="PDF" runat="server">
    69.                                <asp:Literal runat="server" Text="<%$Resources:PDFFieldLabel %>"></asp:Literal>
    70.                            </asp:Label>
    71.                            <asp:TextBox ID="PDF" runat="server" style="display: none;"></asp:TextBox>
    72.                            <asp:Label ID="lblPDFName" runat="server" style="width: 365px; float: left; margin: 5px 5px auto auto;" Text="None selected" />
    73.                            <asp:HiddenField ID="hdnNoPDFMsg" runat="server" Value="None selected"  />
    74.                            <div style="float: left; margin: 5px 5px auto auto;">
    75.                                <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ItemDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" associatedcontrols="PDF,lblPDFName" runat="server" ButtonText="Choose a document" /><span> | </span><span><a href="#" id="lnkRemovePDF">Remove document</a></span>
    76.                            </div>
    77.                        </li>
    78.                    </ol>
    79.                    </div>
    80.                </fieldset>
    81.                <div class="bottom"><div><!-- --></div></div>
    82.            </ItemTemplate>
    83.        </sf:ContentMetaFields>

    Its on line 45 above, called lblLogoName

    Thanks
    higgsy
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Sep 2010
    Link to this post
    Hello Alastair,

    You can try getting it by specifying a traverse method. Works on my side:
    public Label MyLabel
    {
        get
        {
            return base.Container.GetControl<Label>("MyLabel", true, Framework.Web.TraverseMethod.DepthFirst);
        }
    }

    The other option is to find it in the controls collection of the item template of the meta fields control:
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        Label label = (Label)this.MetaFields.Controls[0].FindControl("MyLabel");
        label.Text = "TEXT";
    }

    Kind regards,
    Radoslav Georgiev
    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. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    17 Sep 2010
    Link to this post
    Hi Radoslav,

    Your suggestion actually prompted me to look at using the base class, which ended up with the following code which works:

    protected override void CreateChildControls() {
     
                base.CreateChildControls();
     
                //get logo label
                Label oLogoLabel = base.MetaFields.GetControl("lblLogoName", false) as Label;
     
    }

    Thanks for your help.

    higgsy
Register for webinar
5 posts, 0 answered