Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Controls added to a form programmatically vanish later :(
Message
De
29/03/2004 10:26:30
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Controls added to a form programmatically vanish later :(
Divers
Thread ID:
00890414
Message ID:
00890414
Vues:
80
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform