从自定义用户控件更新contenttemplate下页面中控件的id

Update id of a control in a page under contenttemplate from a custom user control?

本文关键字:控件 id contenttemplate 自定义 用户 更新      更新时间:2023-12-28

我的共享点页面中有一个控件

    <asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<SharePointWebControls:UIVersionedContent UIVersion="4" runat="server">
    <ContentTemplate>
        <asp:Literal runat="server" id="Literal1" text="" visible="false"></asp:Literal>

    i am trying to access this literal1 from a usercontrol and change the text value of this control or change the ID value of  this control. 

我尝试过更新DIV控件的id,但没有成功。这是用户控件的一部分。

      HtmlGenericControl control = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Page.FindControl("literal");
        if (control != null)
        {
            control.Attributes.Clear();
            control.Attributes.Add(ID,divid);
            //control.Text = divid.ToString();
            //document.getElementById('var_div').setAttribute('id',val)
        }

任何人都知道它将如何工作

文本被渲染为零。请尝试使用Label。