Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamicly created repeater and ItemCommand event problem
    primarykey
    data
    text
    <p>A strange problem.<br> On my page i have a placeholder where I create a repeater on run time.<br> In ItemTemplate i have a button that invokes repeater_ItemCommand event. </p> <p>I put a breakpoint on first line of repeater_ItemCommand event, when the button is triggered the event is invoked as planned, <strong>but</strong> after RebindRepeaters() is finished, when i click on the button again repeater_ItemCommand event <strong>is not invoked</strong>! Only if i click on the button one again it invokes, in other scenarios(this is simple version of my page, in original page i have updatepanel that complex everything) it never invokes!</p> <p>My aspx code:</p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;div id="talk"&gt; &lt;asp:PlaceHolder ID="PlaceHolder1" runat="server"&gt;&lt;/asp:PlaceHolder&gt; &lt;/div&gt; </code></pre> <p>My Code-behind:</p> <pre><code>protected void Page_Init(object sender, EventArgs e) { RebindRepeaters(); } void RebindRepeaters() { PlaceHolder1.Controls.Clear(); CreateRepeater(PlaceHolder1); } void CreateRepeater(Control container) { Repeater repeater1 = new Repeater(); repeater1.ItemCommand += new RepeaterCommandEventHandler(repeater_ItemCommand); repeater1.ItemTemplate = Page.LoadTemplate("CommentsTemplate.ascx"); container.Controls.Add(repeater1); repeater1.DataSource = Comment.GetCommentsP(8, 0); repeater1.DataBind(); } void repeater_ItemCommand(object sender, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "Edit": RebindRepeaters(); break; } } </code></pre> <p>The CommentsTemplate.ascx:</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="CommentsTemplate.ascx.cs" Inherits="CommentsTemplate" %&gt; &lt;ul&gt; &lt;li&gt; &lt;div class="show"&gt; &lt;div class="c"&gt; &lt;asp:LinkButton ID="lbtnTitle" runat="server" Text='&lt;%#Eval("EncodedTitle")%&gt;' CausesValidation="false" CommandName="VoteUp" OnClientClick="viewHide(this);return false;" CommandArgument='&lt;%#Eval("ID")%&gt;'&gt;&lt;/asp:LinkButton&gt; &lt;p class="d"&gt;&lt;%#Eval("AddedBy")%&gt;,&lt;%#Eval("AddedDate")%&gt;&lt;/p&gt; &lt;div class="CommentBody"&gt;&lt;%# Eval("EncodedBody") %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="userpanel"&gt; &lt;asp:Panel runat="server" ID="panAdmin" Visible='&lt;%# UserCanEdit %&gt;' style="float:left;"&gt; &lt;asp:ImageButton runat="server" ID="btnSelect" CommandName="Edit" CommandArgument='&lt;%# Eval("ID") %&gt;' CausesValidation="false" AlternateText="Edit comment" ImageUrl="~/Images/Edit.gif" /&gt; &lt;asp:ImageButton runat="server" ID="btnDelete" CommandName="Delete" CommandArgument='&lt;%# Eval("ID") %&gt;' CausesValidation="false" AlternateText="Delete comment" ImageUrl="~/Images/Delete.gif" OnClientClick="if (confirm('Are you sure you want to delete this comment?') == false) return false;" /&gt; &lt;/asp:Panel&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>If you need more info just ask.</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.
 

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