Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET: Custom Control Reloads Whole Page
    text
    copied!<p>I'm working on a ASP.NET site with C# code. Now the trouble starts when I create a custom control programmatically. The control displays in a panel, but when I click one of the buttons of the control it does nothing. If I click them twice, the user control disappears. Using the debugger, I found that it's doing a postback, which is strange because I tried using buttons and setting the <code>usesubmitbehavior</code> to <code>false</code>; it's still sending postbacks.</p> <p>Here is where the control is inserted on the <code>default.aspx</code> file</p> <pre><code>&lt;asp:UpdatePanel runat="server" ID="contentHolderUpdatePanel" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:Panel runat="server" ID="contentPanel"&gt; &lt;/asp:Panel&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p>Here is the ASPX from <code>ListadoAuditoria</code> of the control. </p> <pre><code>&lt;asp:UpdatePanel runat="server" ID="auditorTableUpdatePanel" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:Table runat="server" ID="auditorTable" BorderWidth="0" Width="100%"&gt; &lt;asp:TableHeaderRow HorizontalAlign="Center"&gt; &lt;asp:TableHeaderCell&gt;Button &lt;/asp:TableHeaderCell&gt; &lt;/asp:TableHeaderRow&gt; &lt;/asp:Table&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;asp:UpdatePanel runat="server" ID="formHolderUpdatePanel" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:Label runat="server" ID="testLabel" Text="bbbbbbbbbbbbb" &gt;&lt;/asp:Label&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p>The method that the button invokes should change the text of the label <code>testLabel</code> from "bbbbbbbbbbbbb" to "aaaaaaaaaaa". Obviously I'm doing an <code>auditorTableUpdatePanel.Update()</code> after I modify the text.</p> <p>The control CS</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { loadAudits(); } public void loadAudits() { for(int i=0;i&lt;10;++i) { TableRow row = new TableRow(); TableCell cell1 = new TableCell(); ImageButton deleteButton = new ImageButton(); deleteButton.ImageUrl = "~/image.gif"; deleteButton.Click += generateNewPart; deleteButton.EnableViewState = true; deleteButton.ID = i.ToString(); cell1.Controls.Add(deleteButton); row.Cells.Add(cell1); auditorTable.Rows.Add(row); } } public void generateNewPart(object sender, EventArgs e) { tumadre.Text = "aaaaaaaaaaaa"; formHolderUpdatePanel.Update(); } </code></pre> <p>And here is the code when I generate the control and insert it into the panel:</p> <pre><code>Panel panel = (Panel)Page.FindControl("contentPanel"); UpdatePanel updatePanel = (UpdatePanel)Page.FindControl("contentHolderUpdatePanel"); ListadoAuditorias listadoAuditorias = (ListadoAuditorias)LoadControl("~/CargaDeAuditoria/ListadoAuditorias.ascx"); panel.Controls.Add(listadoAuditorias); updatePanel.Update(); </code></pre> <p>I looked over the Internet and didn't found anything.</p>
 

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