Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Controls added to a form programmatically vanish later :
Message
 
À
29/03/2004 10:26:30
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00890414
Message ID:
00890722
Vues:
21
All server objects are released after the page is posted to the client. The server knows nothing more of the page. When the client postsback, objects that are persisted in the viewstate are recreated on the server and then resolved with forms data on so forth. You may want to look at the getting you new control into viewstate.

~dab


>I often have to create web forms that are read only, but using the disabled color, grey, is not ideal.
>
>I can make text boxes readonly, but dropdown lists and other controls can not be made read only.
>
>I decided to write a function as part of my page class to convert any object I send it into a Text box.
>
>This function would be called from my page refresh code , which runs whenever I need to refresh all the objects on my page after a post back.
>
>So long as the code at the end of the refresh (after any objects have been updated) all should be well, however this is not what happens.
>
>It works fine the firt time it is run, but on subsequent refreshes I discovered that the object I created the first time around has vanished:(
>
>If this is the normal behaviour of objects that are created at execution time it is going to limit what I can create.
>
>
>
>
>
>
>    Overridable Function control2textbox(ByVal targctrl As DropDownList, ByVal strDisplay As String)
>        Dim TbxID As String = "Txt2" + targctrl.ID
>        Dim textbox1 As TextBox
>
>        If Me.FindControl(TbxID) Is Nothing Then
>            textbox1 = New TextBox()
>            Dim lc As HtmlGenericControl = CType(Me.FindControl(targctrl.Parent.ID), HtmlGenericControl)
>            lc.Controls.Add(textbox1)
>        Else
>            textbox1 = Me.FindControl(TbxID)
>        End If
>
>            With textbox1
>            .ID = TbxID
>            .ReadOnly = True
>            .Style("POSITION") = targctrl.Style("POSITION")
>            .Style("TOP") = targctrl.Style("TOP")
>            .Style("LEFT") = targctrl.Style("LEFT")
>            .Style("WIDTH") = targctrl.Style("WIDTH")
>            .Width = targctrl.Width
>            ' textbox1.Text = targctrl.SelectedItem.Value().ToString  '.SelectedItem.Value().ToString
>            .Text = strDisplay 'targctrl.SelectedItem.Text
>            targctrl.Visible = False 'Now make the original control invisible
>
>
>        End With
>    End Function
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform