Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.net UpdatePanel dynamically using C# code
    primarykey
    data
    text
    <p>I have a custom usercontrol that has some Asp.net code. I would like to write the same code but with C#. The problem is that i don't know how to put a repeater and some buttons into the ContentTemplate.</p> <p>The Asp.net Code :</p> <pre><code>&lt;asp:UpdatePanel runat="server" ID="up"&gt; &lt;ContentTemplate&gt; &lt;n2:Repeater ID="rpt" runat="server"&gt; &lt;ItemTemplate&gt;&lt;/ItemTemplate&gt; &lt;/n2:Repeater&gt; &lt;asp:LinkButton runat="server" ID="btnFirst" Visible="false" Enabled="false" Text="&lt;&lt;" OnClick="btnFirst_Click" /&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p>So how could I write this chunk in C# code? To be precise, how could I insert the repeater and the Linkbutton into the ContentTemplate.</p> <p>Note : I don't want to use the LoadTemplate to do it.</p> <p><strong>Edit</strong></p> <p>I have tried ContentTemplateContainer.Controls.Add():</p> <pre><code> private UpdatePanel up = new UpdatePanel(); private Repeater rpt = Repeater();; public Paging{ //Add repeater to updatePanel up.ContentTemplateContainer.Controls.Add(rpt); AsyncPostBackTrigger apb3 = new AsyncPostBackTrigger(); apb3.ControlID = "btnFirst"; apb3.EventName = "Click"; //Add Triggers to updatePanel up.Triggers.Add(apb1); //Create buttons btnFirst = new LinkButton(); btnFirst.Visible = false; btnFirst.Enabled = false; btnFirst.Text = "&lt;&lt;"; btnFirst.Click += new EventHandler(btnFirst_Click); //Add buttons to update panel up.ContentTemplateContainer.Controls.Add(btnFirst); } protected void Page_Load(object sender, EventArgs e) { rpt.ItemTemplate = LoadTemplate("~/UI/Templates/NewsEvent.ascx"); .... } </code></pre> <p>I have an error caused by the first line on Page_Load : <em>Databinding methods such as Eval(), XPath(), and Bind() can only be used in controls contained in a page.</em></p> <p>This is NewsEvent.ascx:</p> <pre><code>&lt;img src='&lt;%# Eval("ImageThumbnail") %&gt;' alt="" /&gt; </code></pre>
    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.
 

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