locked
Custom TextBox Webcontrol RRS feed

  • Question

  • User2062749751 posted

    Hi ,

    This may be a stupid question but I am newbie in ASP.Net.

    I created a custom [Textbox] Webcontrol. When i try to get the text from this control it always returns nothing!!  
     
    Is this a viewstate issue?

    I am not sure what is wrong with the code.

    Any help would be appreciated..

    Here is the Rendering Code

    Protected Overrides Sub CreateChildControls()
            TextBox = New WebControls.TextBox
            TextBox.Font.Name = "Verdana"
            TextBox.Font.Size = FontUnit.Point(8)
            TextBox.Style("z-index") = "1000"
            Controls.Add(TextBox)
        End Sub
    
        Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
            EnsureChildControls()
            TextBox.ID = ID
            'TextBox.Text = Text
            TextBox.Style("class") = CssClass
            If Not Left.IsEmpty Then
                TextBox.Style("LEFT") = Left.ToString
            End If
            If Not Top.IsEmpty Then
                TextBox.Style("TOP") = Top.ToString
            End If
            If Not PasswordLength = 0 Then
                TextBox.Attributes("onChange") += "CheckLength(this);"
            End If
            TextBox.Height = Height
            TextBox.Width = Width
            'TextBox.Style("filter") = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#2222333f', EndColorStr='#ffffeeee')"
            If IsPasswordBox Then
                TextBox.TextMode = TextBoxMode.Password
                TextBox.Attributes("onChange") += "CheckLength(this," & PasswordLength & ")"
            Else
                TextBox.TextMode = TextBoxMode.SingleLine
            End If
            SetPositioning(TextBox)
            RenderChildren(output)
        End Sub

    And here is the code where I try to access the value from the textbox.

     Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
            Dim log As MyLogin
            log.UserName = txtUserName.Text
        End Sub
    
     



    Thanks in Advance....
    Friday, April 18, 2008 12:28 PM

Answers

  • User-16411453 posted

     You have to render the control to the screen

     

     Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
            
    	RenderContents(output)
    
        End Sub
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 20, 2008 1:44 PM

All replies

  • User1094523028 posted

     Well, the best advice I can give you is to ask yourself if you really need a Sever Control, or if a user control would be fine.  It looks like you are writing a Server Control since you are Dynamically creating the TextBox, are you?  If this is a control that you are only going to use in this project you probably will be fine using a User Control.  User Controls are easier to make and use because you do not have to deal with the render method or CreateChildControls.

    If you really do have to make a Server Control, since you stated that you are a newbie I would not recommend it, you should read up on this series of blogs,

    http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx 

    Friday, April 18, 2008 2:45 PM
  • User2062749751 posted

    Thanks for the link it was really helpfull on how to dynamically create controls.

    but my question remained unanswered. Could anyone please guide me to a link or a walkthrough where a Textbox control is customized

     Thanks

    Friday, April 18, 2008 5:23 PM
  • User-16411453 posted

     You have to render the control to the screen

     

     Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
            
    	RenderContents(output)
    
        End Sub
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 20, 2008 1:44 PM