I am having a weird situation which I cannot find a way to resolve.
I have a form with various controls (labels, buttons, etc.). All the labels, based on their ID, following a naming convention, are being assigned their proper values based on the language selected by the user, where the labels come from Message.dbf. So, when the form appears, all the labels have their proper values.
In that form, near the end, I have something like this:
<asp:Label ID="Style" runat="server">
which acts as a place holder as the code behind need to know from where to add some additional controls. So, the code behind does something like this:
loControlForm = oApp.oPage.FindControl("Form1")
loControl = oApp.oPage.FindControl(tcControl)
lnIndex = loControlForm.Controls.IndexOf(loControl)
loControlLiteral = New System.Web.UI.WebControls.Literal
loControlLiteral.Text = "<TABLE CELLSPACING=0 CELLPADDING=0><TR VALIGN=TOP><TD>"
loControlForm.Controls.AddAt(lnIndex + 1, loControlLiteral)
lnIndex = lnIndex + 1
loControlLiteral = New System.Web.UI.WebControls.Literal
loControlLiteral.Text = "</TABLE>"
loControlForm.Controls.AddAt(lnIndex + 1, loControlLiteral)
...where loControl represents the Style label. So, basically, from that location, I can add some literals and other controls. In this example, I only showed the addition of the starting table and the end table as controls.
After the Style label, I have other labels. So, all the other labels, following that place holder label markup, are being initialized ok as per the language used by the user.
So, everything works ok. When the form loads, all the labels are properly assigned and several controls are being added from the location of where the Style label is.
The problem is on the postback. Everything appears ok on the form until the Style label, which acts as a place holder for the addition of the controls I need. Basically, the problem is with the first AddAt(). On postback, as soon as the first AddAt() is executed, this somewhat confuses the reendering of the form and the names of all the controls, and all other labels following that location are not initialized. So, again, this only behaves like that on postback. I don't know how to find a workaround that will make the addition of those controls works without affecting the postback values which should be there as when the form was loaded at first.