Note that there are some explanatory texts on larger screens.

plurals
  1. POClient ID When Overriding Render Method
    text
    copied!<p>I'm using a custom web control where the Render method was overriden.</p> <p>My problem is that the ID of the rendered control does not include IDs the master pages and user controls where the control is located.</p> <p>Meaning that if my render method includes the following:</p> <pre><code>writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderEndTag(); </code></pre> <p>And it is used as follows:</p> <pre><code>&lt;somePrefix:MyWebControl ID="WebControl1" runat="server" /&gt; </code></pre> <p>Then the control will be rendered as:</p> <pre><code>&lt;div id="WebControl1"&gt;&lt;/div&gt; </code></pre> <p>While I want something like:</p> <pre><code>&lt;div id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolderMain_WebControl1"&gt;&lt;/div&gt; </code></pre> <p>(which is what would be generated if I put up a div with the ID WebControl1 and runat="server")</p> <p>What can I do to achieve that?</p> <p><strong>Edit</strong></p> <p>I was wrong regarding when this is happening. When I place the control directly in the page, the id is fine (asp.net generated id).</p> <p>However, the problem occurs when MyControl is rendered from another web controls, which holds a collection of my controls.</p> <p>In the container control the RenderControl method is overriden as follows:</p> <pre><code>foreach (Control control in MyControls) { divControls.Controls.Add(control); } divControls.RenderControl(writer) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload