Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Table Causes 500 Error after PostBack Occurs
    primarykey
    data
    text
    <p>Good day! I've spent quite a few hours trying to figure this one out and now I need some help.</p> <p>I have an ASP.NET AjaxToolKit <code>TabContainer</code> which has four <code>TabPanel</code> children. Each of these children has it's own <code>UpdatePanel</code> so I can run the logic in each panel without reloading everything (AJAX).</p> <p>Here's my problem:</p> <p>In my SECOND<code>TabPanel</code> I have some markup that looks like this:</p> <pre><code>&lt;div id="ProgramMilestonesDiv" style="margin-left: 6px;"&gt; &lt;asp:Table ID="ProgramMilestonesTable" runat="server" Visible="true"&gt; &lt;/asp:Table&gt; &lt;/div&gt; </code></pre> <p>In my <code>Page_Init</code> routine I dynamically add row/cells/labels/texboxes to the control.</p> <p>When I do a postback in the SECOND <code>TabPanel</code>, any postbacks in the FIRST <code>TabPanel</code> now cause a 500 error to be returned from the server. If I never do a postback in the SECOND, the FIRST postback runs fine. This is even if I don't put any values in the dynamically created controls for the table (i.e., I'm not putting any invalid characters in there to trip the page validation).</p> <p>If I remove the dynamic creation of the textboxes it works, but I'm stumped as to why because they are blank AND I've made sure all the control IDs are unique. I even have a bunch of other dynamically created textboxes on the page, using the same code-behind method for doing so, and they work fine (they are in tables in <code>Accordion</code> controls).</p> <p>Any suggestions on what might be going wrong? Any suggestions on debugging it to see the specific reason it is failing?</p> <p>My code-behind for creating the textboxes looks like this:</p> <pre><code> public static void AddVariableCostRowToTable(Table TargetTable, string CostArea, string CostType, Extender Extender) { string[] quarters = { "Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", "Q11", "Q12" }; TableRow row = new TableRow(); // New row we'll add to table. // First cell is just the name of the cost. TableCell cell = new TableCell(); Label label = new Label(); label.Width = new Unit(175); label.Text = CostType.Replace('_', ' ') + ":"; cell.Controls.Add(label); row.Controls.Add(cell); // Create all the textboxes for the individual quarters. foreach (string q in quarters) { row.Controls.Add(CreateNewCellWithTextBox(CostArea, CostType, q, Extender)); } TargetTable.Controls.Add(row); // Add the row to the table. } public static TableCell CreateNewCellWithTextBox(string CostArea, string CostType, string Quarter, Extender Extender) { TableCell cell = new TableCell(); TextBox textbox = new TextBox(); textbox.ID = CostArea + CostType + Quarter; // string textbox.Width = new Unit(65); // Pixels wide. textbox.Text = ""; if (Extender == Extender.MASKED_EDIT_EXTENDER) textbox.Text = "0"; // Only initialize to 0 if textbox is for money. textbox.Style.Add(HtmlTextWriterStyle.TextAlign, "right"); textbox.ClientIDMode = ClientIDMode.Static; cell.Controls.Add(textbox); if (Extender == Extender.MASKED_EDIT_EXTENDER) // If calling routine wanted a $$$ filter on the textbox. { // Add an ajaxtoolkit extender so we can enforce currency formatting. MaskedEditExtender extender = new MaskedEditExtender(); extender.ID = "MaskedEditExtender" + textbox.ID; extender.TargetControlID = textbox.ID; extender.Mask = "999999"; extender.OnFocusCssClass = "MaskedEditFocus"; extender.MaskType = MaskedEditType.Number; extender.InputDirection = MaskedEditInputDirection.RightToLeft; extender.AcceptNegative = MaskedEditShowSymbol.Left; extender.DisplayMoney = MaskedEditShowSymbol.Left; cell.Controls.Add(extender); } return cell; } </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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