Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'v been doing it like this. Take this as an example RenderingTemplate:</p> <pre><code>&lt;SharePoint:RenderingTemplate ID="ParentItemsListView" runat="server"&gt; &lt;Template&gt; &lt;table cellpadding=0 cellspacing=0&gt; &lt;tr&gt;&lt;td nowrap class="UserGenericHeader"&gt;&lt;asp:Label ID="lblParentItems" runat="server" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;SharePoint:ListViewByQuery ID="listViewByQuery" runat="server" /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/Template&gt; &lt;/SharePoint:RenderingTemplate&gt; </code></pre> <p>Then in Render event i can reference these controls like this:</p> <pre><code> [SharePointPermission(SecurityAction.Demand, ObjectModel = true)] protected override void Render(HtmlTextWriter output) { if (this.Visible) { Label lblParentItems = this.TemplateContainer.FindControlRecursive&lt;Label&gt;("lblParentItems"); lblParentItems.Text = "Pievienotie " + this.ChildList.Title; ListViewByQuery listView = TemplateContainer.FindControlRecursive&lt;ListViewByQuery&gt;("listViewByQuery"); listView.List = this.ChildList; ... base.Render(output); } } </code></pre> <p>Ahh, yes, i use a handy extension function</p> <pre><code>public static T FindControlRecursive&lt;T&gt;(this Control parentControl, string id) where T : Control { T ctrl = default(T); if ((parentControl is T) &amp;&amp; (parentControl.ID == id)) return (T)parentControl; foreach (Control c in parentControl.Controls) { ctrl = c.FindControlRecursive&lt;T&gt;(id); if (ctrl != null) break; } return ctrl; } </code></pre> <p>However i had an issue where i inherited from <code>SaveButton</code> that i couldn't reference a control. In that case i changed so that i inherit from <code>FormControl</code> and i could find my control under <code>this.Controls</code>.</p> <p>Also note that you cannot reference controls up until OnLoad event has executed (i.e if you're in OnLoad function, call <code>base.OnLoad(e)</code> before referencing controls.</p> <p>Why is it so? I guess because it's not like you are having a template and then code behind (working with the same class/object), but it's more like you are rendering that ascx template in a different class/object file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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