Dynamically I create at the Page_Load stage in the table on the page the usual controls: texbox, combobox, checkbox - everything is normally created, displayed, handlers are processed. I try to create a calendar - it does not issue errors, but the control does not appear in the DOM either.

Dim newDtEl As New Calendar newDtEl.ID = spElement.getAttribute("id") newDtEl.AutoPostBack = True spCell.Controls.Add(newDtEl) 

Where am I wrong? What could be the snag? How to make it appear? The table is declared in aspx:

 <table width="50%" align="center" id="ElTable" runat="server"> <tbody> <tr> <td>Date</td> <td><asp:calendar ID="dasd" runat="server"></asp:calendar></td> </tr> <tr> <td>UserDate</td> <td><uc1:UserControlWithCalendar ID="Calendar1" runat="server"></uc1:UserControlWithCalendar></td> </tr> </tbody> </table> 

This is how these controls are displayed. I add a row and a cell dynamically like this:

 Dim spRow As New HtmlTableRow, spCell As New HtmlTableCell spRow.Cells.Add(spCell) ElTable.Rows.Add(spRow) 

.NET Framework 2.0, VS2005

  • In your TextBox example, should a calendar appear on it when clicked? - kmv
  • Error, incorrectly indicated. just now I have done textbox with date validation, but this is not exactly what is needed. - Yuri
  • Can you add to the question the code for creating spCell and the code for creating the table in which they are located? - kmv
  • You have a row and a cell in the table correctly added, i.e. something like spRow.Cells.Add(spCell) and ElTable.Rows.Add(spRow) ? - kmv
  • Yes exactly. - Yuri

1 answer 1

Here is a minimal example + your markup work out normally, the calendar is created:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim spRow As New HtmlTableRow, spCell As New HtmlTableCell Dim newDtEl As New Calendar newDtEl.ID = "calTest" ' у календаря нет свойства AutoPostBack ' spCell.Controls.Add(newDtEl) spRow.Cells.Add(New HtmlTableCell With {.InnerText = "test"}) spRow.Cells.Add(spCell) ElTable.Rows.Add(spRow) End Sub 
  • Ideally, this is how it should be - this is what I started, but it does not work. version of .NET Framework 2.0, VS2005 - can it be critical? - Yuri
  • The idea should not affect. Maybe you put Visible = false somewhere for a table or another parent control? Then the controls and all the controls embedded in it will not be created. - kmv
  • No, I do not touch visible at all. Only at a cell I change width at initialization. No other actions with the table yet. The table itself is displayed normally, the rest of the controls, which are also added, too. The trouble is only with the calendar. Well, with usercontrol, but I think the problem is common. - Yuri