Quesiton about user controls


C

Carlo Razzeto

Quick question....

So with ASP controls, you can do the following in the code behind and have
the control render on the webpage:

TableCell Cell = TabRow.Cells(0);
Cell.Controls.Add(new System.web.ui.webcontrols.textbox());

I've created a series of web user controls, and I of course put all the UI
HTML elements into the ascx file. What I've found is that if I do the
following

TableCell Cell = TabRow.Cells(0);
SocialSecurityNumber txtSSN = new SocialSecurityNumber();
txtSSN.ID = "txtSSN";
Cell.Controls.Add(txtSSN);

The control does not render on page. Anyone know if there is a trick to
make
this work? Or do all UI elements need to be written to the output stream
via
Response.Write()?

Thanks, below is the user controls code. The parent class is a custom class
I wrote that inherits from system.web.ui.usercontrol, it's there to provide
certain company specific functionality

======================================

Public Partial Class SocialSecurityNumber
Inherits CompanyUserControl
#Region "Fields"
Private __cssClass As String = ""
Private __text As String = ""
Private __onKeyUpEvent As System.Text.StringBuilder = Nothing
#End Region

#Region "ASP Event Handlers"
''' <summary>
''' PreRender event handler
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Init
__text = Request.Form(ID)
End Sub

''' <summary>
''' Prerender event
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.PreRender

End Sub
#End Region

#Region "Properties"
#Region "Internal Properties"
''' <summary>
''' Text for the on change event handler
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Protected ReadOnly Property OnKeyUpEvent() As String
Get
If __onKeyUpEvent Is Nothing Then
__onKeyUpEvent = New System.Text.StringBuilder()
__onKeyUpEvent.Append("ssnBox_validateSSN( '" + UniqueID +
"' );")
End If
Return __onKeyUpEvent.ToString()
End Get
End Property

''' <summary>
''' Gets a safe version of the text for
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Protected ReadOnly Property SafeText() As String
Get
Return CommonFunctions.GetSafeInputString(Text)
End Get
End Property
#End Region

#Region "Public Properties"
''' <summary>
''' Css Class
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property CssClass() As String
Get
Return __cssClass
End Get
Set(ByVal value As String)
__cssClass = value
End Set
End Property

''' <summary>
''' Text property
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Text() As String
Get
Return __text
End Get
Set(ByVal value As String)
__text = value
End Set
End Property
#End Region
#End Region
End Class
 
Ad

Advertisements

C

Carlo Razzeto

Update:
So I tried out another control I wrote which actually uses some asp controls
in the ascx, like a text box and I've found that the ascx/designer is
probably not being executed. When I try to include that control I get a null
reference to the textbox :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top