Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding controls on postback causes a problem
Message
 
 
To
29/06/2006 18:42:30
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01132934
Message ID:
01132952
Views:
15
>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:
>
>
>            ' Find the form control
>            loControlForm = oApp.oPage.FindControl("Form1")
>
>            ' Find the MenuOptions control
>            loControl = oApp.oPage.FindControl(tcControl)
>
>            lnIndex = loControlForm.Controls.IndexOf(loControl)
>
>            ' Table header
>            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
>
>            ' Table footer
>            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.


I am not surprised ASP can't add a control at Postback time. It probably has its own collection of controls that are on the page and can't handle additional ones on the fly.

Possible workaround -- is the number of additional controls fixed or variable? If it's fixed, you could define them to begin with, invisible, then make them visible at the appropriate time.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform