473,883 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading UserControl using New Contructor

Joe
Hello All:

Do I have to use the LoadControl method of the Page to load a UserControl?

I have a class which contains three methods (one public and two private).
The class acts as a control server. It "serves" back the required control
(either WebControl or UserControl) based on the contents of an xml file. The
code in the webform places each control in a TableCell.

My problem is that the control server works as far as returning the correct
control; but when I view the webform, the UserControl is nowhere to be found.
It's not on the page and not in the View Source.

Here is the server code (I'm not posting GetWebControl here):

Public Function GetControl(ByVa l NodeToRender As XmlNode) As
Web.UI.Control
Dim ValueToMatch As String
If NodeToRender.Na me.Equals("Disp layText") Then
ValueToMatch = NodeToRender.Na me.ToLower
Else
ValueToMatch = NodeToRender.At tributes("type" ).Value.ToLower
End If
Select Case ValueToMatch.To Lower
Case "label", "textbox", "checkbox", "displaytex t"
Return GetWebControl(N odeToRender)

Case "customaddresse s"
Return GetUserControl( NodeToRender)

End Select
End Function

Private Function GetUserControl( ByVal NodeToRender As XmlNode) As
Web.UI.UserCont rol
Dim uControl As New CustomAddresses

uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
Return uControl
End Function

Here is the code and HTML for the UserControl (called CustomAddresses ):

Public Class CustomAddresses
Inherits System.Web.UI.U serControl

Public Sub New()
Addr1 = New TextBox
Addr2 = New TextBox
Addr3 = New TextBox
Addr4 = New TextBox
End Sub

Public Sub PopulateAddress Boxes(ByVal str As String)
Dim SelectedValue() As String = str.Split(("/").ToCharArray( ))
Dim Name As String = SelectedValue(0 ).Trim
Dim Address() As String = SelectedValue(1 ).Split((",").T oCharArray())
Dim Addr1 As String = Address(0).Trim
Dim Addr2 As String = Address(1).Trim
Dim City As String = Address(Address .Length - 3).Trim
Dim StateProvCd As String = Address(Address .Length - 2).Trim
Dim PostalCode As String = Address(Address .Length - 1).Trim

Me.Addr1.Text = Name
Me.Addr2.Text = Addr1
If Not Addr2.Equals(Ci ty) Then
Me.Addr3.Text = Addr2
Me.Addr4.Text = City & " " & StateProvCd & ", " & PostalCode
Else
Me.Addr3.Text = City & " " & StateProvCd & ", " & PostalCode
End If
End Sub
End Class

<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Cus tomAddresses.as cx.vb" Inherits="WBMI. Claims.CustomAd dresses"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
<TABLE class="interior " id="Table1" width="100%">
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr1" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr2" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr3" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr4" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
</TABLE>

Here's a sample of the webform code that calls these:

If TypeOf SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
WebControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
WebControl)

ElseIf TypeOf
SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
UserControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
UserControl)

End If
NewCell.Control s.Add(ControlTo Render)

What this boils down to is that I want to create and utilize a ControlServer
class to encapsulate the details about how a control is created and returned.

Can this be done?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Dec 22 '05 #1
12 2220
Joe
I figured out that I have to override the Render method in the UserControl.

I do not really understand the HtmlTextWriter. How do I write populated
TextBox controls to the webform?

Thank you for any available help.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Joe" wrote:
Hello All:

Do I have to use the LoadControl method of the Page to load a UserControl?

I have a class which contains three methods (one public and two private).
The class acts as a control server. It "serves" back the required control
(either WebControl or UserControl) based on the contents of an xml file. The
code in the webform places each control in a TableCell.

My problem is that the control server works as far as returning the correct
control; but when I view the webform, the UserControl is nowhere to be found.
It's not on the page and not in the View Source.

Here is the server code (I'm not posting GetWebControl here):

Public Function GetControl(ByVa l NodeToRender As XmlNode) As
Web.UI.Control
Dim ValueToMatch As String
If NodeToRender.Na me.Equals("Disp layText") Then
ValueToMatch = NodeToRender.Na me.ToLower
Else
ValueToMatch = NodeToRender.At tributes("type" ).Value.ToLower
End If
Select Case ValueToMatch.To Lower
Case "label", "textbox", "checkbox", "displaytex t"
Return GetWebControl(N odeToRender)

Case "customaddresse s"
Return GetUserControl( NodeToRender)

End Select
End Function

Private Function GetUserControl( ByVal NodeToRender As XmlNode) As
Web.UI.UserCont rol
Dim uControl As New CustomAddresses

uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
Return uControl
End Function

Here is the code and HTML for the UserControl (called CustomAddresses ):

Public Class CustomAddresses
Inherits System.Web.UI.U serControl

Public Sub New()
Addr1 = New TextBox
Addr2 = New TextBox
Addr3 = New TextBox
Addr4 = New TextBox
End Sub

Public Sub PopulateAddress Boxes(ByVal str As String)
Dim SelectedValue() As String = str.Split(("/").ToCharArray( ))
Dim Name As String = SelectedValue(0 ).Trim
Dim Address() As String = SelectedValue(1 ).Split((",").T oCharArray())
Dim Addr1 As String = Address(0).Trim
Dim Addr2 As String = Address(1).Trim
Dim City As String = Address(Address .Length - 3).Trim
Dim StateProvCd As String = Address(Address .Length - 2).Trim
Dim PostalCode As String = Address(Address .Length - 1).Trim

Me.Addr1.Text = Name
Me.Addr2.Text = Addr1
If Not Addr2.Equals(Ci ty) Then
Me.Addr3.Text = Addr2
Me.Addr4.Text = City & " " & StateProvCd & ", " & PostalCode
Else
Me.Addr3.Text = City & " " & StateProvCd & ", " & PostalCode
End If
End Sub
End Class

<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Cus tomAddresses.as cx.vb" Inherits="WBMI. Claims.CustomAd dresses"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
<TABLE class="interior " id="Table1" width="100%">
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr1" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr2" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr3" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr4" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
</TABLE>

Here's a sample of the webform code that calls these:

If TypeOf SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
WebControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
WebControl)

ElseIf TypeOf
SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
UserControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
UserControl)

End If
NewCell.Control s.Add(ControlTo Render)

What this boils down to is that I want to create and utilize a ControlServer
class to encapsulate the details about how a control is created and returned.

Can this be done?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

Dec 22 '05 #2
Can you clarify more why you don't want to call LoadControl to load the
control. The reason LoadControl exists is so that ASP.NET has the ability
to prepare the object has it expects such as loading the ASCX and creating
an object model. If you create one with a constructor, then you prevent the
engine from doing what it was suppose to.

All controls have the Render method, but you should not override that in a
usercontrol. There are such things as custom web controls which inherit
from WebControl which you can then override the Render method.

All the HtmlTextWriter does is allow you to output the HTML. A textbox is
nothing more than <input type="text" value="somethin g"/>.
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:0F******** *************** ***********@mic rosoft.com...
I figured out that I have to override the Render method in the UserControl.

I do not really understand the HtmlTextWriter. How do I write populated
TextBox controls to the webform?

Thank you for any available help.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Joe" wrote:
Hello All:

Do I have to use the LoadControl method of the Page to load a
UserControl?

I have a class which contains three methods (one public and two private).
The class acts as a control server. It "serves" back the required
control
(either WebControl or UserControl) based on the contents of an xml file.
The
code in the webform places each control in a TableCell.

My problem is that the control server works as far as returning the
correct
control; but when I view the webform, the UserControl is nowhere to be
found.
It's not on the page and not in the View Source.

Here is the server code (I'm not posting GetWebControl here):

Public Function GetControl(ByVa l NodeToRender As XmlNode) As
Web.UI.Control
Dim ValueToMatch As String
If NodeToRender.Na me.Equals("Disp layText") Then
ValueToMatch = NodeToRender.Na me.ToLower
Else
ValueToMatch = NodeToRender.At tributes("type" ).Value.ToLower
End If
Select Case ValueToMatch.To Lower
Case "label", "textbox", "checkbox", "displaytex t"
Return GetWebControl(N odeToRender)

Case "customaddresse s"
Return GetUserControl( NodeToRender)

End Select
End Function

Private Function GetUserControl( ByVal NodeToRender As XmlNode) As
Web.UI.UserCont rol
Dim uControl As New CustomAddresses

uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
Return uControl
End Function

Here is the code and HTML for the UserControl (called CustomAddresses ):

Public Class CustomAddresses
Inherits System.Web.UI.U serControl

Public Sub New()
Addr1 = New TextBox
Addr2 = New TextBox
Addr3 = New TextBox
Addr4 = New TextBox
End Sub

Public Sub PopulateAddress Boxes(ByVal str As String)
Dim SelectedValue() As String = str.Split(("/").ToCharArray( ))
Dim Name As String = SelectedValue(0 ).Trim
Dim Address() As String =
SelectedValue(1 ).Split((",").T oCharArray())
Dim Addr1 As String = Address(0).Trim
Dim Addr2 As String = Address(1).Trim
Dim City As String = Address(Address .Length - 3).Trim
Dim StateProvCd As String = Address(Address .Length - 2).Trim
Dim PostalCode As String = Address(Address .Length - 1).Trim

Me.Addr1.Text = Name
Me.Addr2.Text = Addr1
If Not Addr2.Equals(Ci ty) Then
Me.Addr3.Text = Addr2
Me.Addr4.Text = City & " " & StateProvCd & ", " & PostalCode
Else
Me.Addr3.Text = City & " " & StateProvCd & ", " & PostalCode
End If
End Sub
End Class

<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Cus tomAddresses.as cx.vb"
Inherits="WBMI. Claims.CustomAd dresses"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
<TABLE class="interior " id="Table1" width="100%">
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr1" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr2" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr3" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr4" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
</TABLE>

Here's a sample of the webform code that calls these:

If TypeOf SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
Is
WebControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
WebControl)

ElseIf TypeOf
SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
UserControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
UserControl)

End If
NewCell.Control s.Add(ControlTo Render)

What this boils down to is that I want to create and utilize a
ControlServer
class to encapsulate the details about how a control is created and
returned.

Can this be done?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

Dec 22 '05 #3
Joe
Hi Peter,

We are using an xml document to "drive" the creation of web pages. The
document defines what controls to include on a webform and where where the
controls will appear.

I have alot of lead-way in defining how the document will be structured and
used.

My idea was to have a class to encapsulate the generation of the required
control (be it a WebControl or a UserControl) and returns it to the webform.
In this app, a UserControl is just a grouping of WebControls. For example,
one UserControl (CustomAddresse s) is four textbox server controls grouped
together for name, address1, address2 and city-state-zip. This will be used
on the page when it will display a person's addresses.

Does this help you understand hat I am really trying to do?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Peter Rilling" wrote:
Can you clarify more why you don't want to call LoadControl to load the
control. The reason LoadControl exists is so that ASP.NET has the ability
to prepare the object has it expects such as loading the ASCX and creating
an object model. If you create one with a constructor, then you prevent the
engine from doing what it was suppose to.

All controls have the Render method, but you should not override that in a
usercontrol. There are such things as custom web controls which inherit
from WebControl which you can then override the Render method.

All the HtmlTextWriter does is allow you to output the HTML. A textbox is
nothing more than <input type="text" value="somethin g"/>.
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:0F******** *************** ***********@mic rosoft.com...
I figured out that I have to override the Render method in the UserControl.

I do not really understand the HtmlTextWriter. How do I write populated
TextBox controls to the webform?

Thank you for any available help.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Joe" wrote:
Hello All:

Do I have to use the LoadControl method of the Page to load a
UserControl?

I have a class which contains three methods (one public and two private).
The class acts as a control server. It "serves" back the required
control
(either WebControl or UserControl) based on the contents of an xml file.
The
code in the webform places each control in a TableCell.

My problem is that the control server works as far as returning the
correct
control; but when I view the webform, the UserControl is nowhere to be
found.
It's not on the page and not in the View Source.

Here is the server code (I'm not posting GetWebControl here):

Public Function GetControl(ByVa l NodeToRender As XmlNode) As
Web.UI.Control
Dim ValueToMatch As String
If NodeToRender.Na me.Equals("Disp layText") Then
ValueToMatch = NodeToRender.Na me.ToLower
Else
ValueToMatch = NodeToRender.At tributes("type" ).Value.ToLower
End If
Select Case ValueToMatch.To Lower
Case "label", "textbox", "checkbox", "displaytex t"
Return GetWebControl(N odeToRender)

Case "customaddresse s"
Return GetUserControl( NodeToRender)

End Select
End Function

Private Function GetUserControl( ByVal NodeToRender As XmlNode) As
Web.UI.UserCont rol
Dim uControl As New CustomAddresses

uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
Return uControl
End Function

Here is the code and HTML for the UserControl (called CustomAddresses ):

Public Class CustomAddresses
Inherits System.Web.UI.U serControl

Public Sub New()
Addr1 = New TextBox
Addr2 = New TextBox
Addr3 = New TextBox
Addr4 = New TextBox
End Sub

Public Sub PopulateAddress Boxes(ByVal str As String)
Dim SelectedValue() As String = str.Split(("/").ToCharArray( ))
Dim Name As String = SelectedValue(0 ).Trim
Dim Address() As String =
SelectedValue(1 ).Split((",").T oCharArray())
Dim Addr1 As String = Address(0).Trim
Dim Addr2 As String = Address(1).Trim
Dim City As String = Address(Address .Length - 3).Trim
Dim StateProvCd As String = Address(Address .Length - 2).Trim
Dim PostalCode As String = Address(Address .Length - 1).Trim

Me.Addr1.Text = Name
Me.Addr2.Text = Addr1
If Not Addr2.Equals(Ci ty) Then
Me.Addr3.Text = Addr2
Me.Addr4.Text = City & " " & StateProvCd & ", " & PostalCode
Else
Me.Addr3.Text = City & " " & StateProvCd & ", " & PostalCode
End If
End Sub
End Class

<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Cus tomAddresses.as cx.vb"
Inherits="WBMI. Claims.CustomAd dresses"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
<TABLE class="interior " id="Table1" width="100%">
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr1" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr2" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr3" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
<TR>
<TD class="tabledat a">
<asp:TextBox id="Addr4" runat="server" Width="361px" ReadOnly="False "
MaxLength="60"> </asp:TextBox></TD>
</TR>
</TABLE>

Here's a sample of the webform code that calls these:

If TypeOf SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
Is
WebControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
WebControl)

ElseIf TypeOf
SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
UserControl Then
ControlToRender =
CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
UserControl)

End If
NewCell.Control s.Add(ControlTo Render)

What this boils down to is that I want to create and utilize a
ControlServer
class to encapsulate the details about how a control is created and
returned.

Can this be done?

TIA,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Dec 22 '05 #4
I don't think this explains why you are against using LoadControl.

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
Hi Peter,

We are using an xml document to "drive" the creation of web pages. The
document defines what controls to include on a webform and where where the
controls will appear.

I have alot of lead-way in defining how the document will be structured
and
used.

My idea was to have a class to encapsulate the generation of the required
control (be it a WebControl or a UserControl) and returns it to the
webform.
In this app, a UserControl is just a grouping of WebControls. For
example,
one UserControl (CustomAddresse s) is four textbox server controls grouped
together for name, address1, address2 and city-state-zip. This will be
used
on the page when it will display a person's addresses.

Does this help you understand hat I am really trying to do?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Peter Rilling" wrote:
Can you clarify more why you don't want to call LoadControl to load the
control. The reason LoadControl exists is so that ASP.NET has the
ability
to prepare the object has it expects such as loading the ASCX and
creating
an object model. If you create one with a constructor, then you prevent
the
engine from doing what it was suppose to.

All controls have the Render method, but you should not override that in
a
usercontrol. There are such things as custom web controls which inherit
from WebControl which you can then override the Render method.

All the HtmlTextWriter does is allow you to output the HTML. A textbox
is
nothing more than <input type="text" value="somethin g"/>.
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:0F******** *************** ***********@mic rosoft.com...
>I figured out that I have to override the Render method in the
>UserControl.
>
> I do not really understand the HtmlTextWriter. How do I write
> populated
> TextBox controls to the webform?
>
> Thank you for any available help.
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
> "Joe" wrote:
>
>> Hello All:
>>
>> Do I have to use the LoadControl method of the Page to load a
>> UserControl?
>>
>> I have a class which contains three methods (one public and two
>> private).
>> The class acts as a control server. It "serves" back the required
>> control
>> (either WebControl or UserControl) based on the contents of an xml
>> file.
>> The
>> code in the webform places each control in a TableCell.
>>
>> My problem is that the control server works as far as returning the
>> correct
>> control; but when I view the webform, the UserControl is nowhere to be
>> found.
>> It's not on the page and not in the View Source.
>>
>> Here is the server code (I'm not posting GetWebControl here):
>>
>> Public Function GetControl(ByVa l NodeToRender As XmlNode) As
>> Web.UI.Control
>> Dim ValueToMatch As String
>> If NodeToRender.Na me.Equals("Disp layText") Then
>> ValueToMatch = NodeToRender.Na me.ToLower
>> Else
>> ValueToMatch =
>> NodeToRender.At tributes("type" ).Value.ToLower
>> End If
>> Select Case ValueToMatch.To Lower
>> Case "label", "textbox", "checkbox", "displaytex t"
>> Return GetWebControl(N odeToRender)
>>
>> Case "customaddresse s"
>> Return GetUserControl( NodeToRender)
>>
>> End Select
>> End Function
>>
>> Private Function GetUserControl( ByVal NodeToRender As XmlNode) As
>> Web.UI.UserCont rol
>> Dim uControl As New CustomAddresses
>>
>> uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
>> Return uControl
>> End Function
>>
>> Here is the code and HTML for the UserControl (called
>> CustomAddresses ):
>>
>> Public Class CustomAddresses
>> Inherits System.Web.UI.U serControl
>>
>> Public Sub New()
>> Addr1 = New TextBox
>> Addr2 = New TextBox
>> Addr3 = New TextBox
>> Addr4 = New TextBox
>> End Sub
>>
>> Public Sub PopulateAddress Boxes(ByVal str As String)
>> Dim SelectedValue() As String = str.Split(("/").ToCharArray( ))
>> Dim Name As String = SelectedValue(0 ).Trim
>> Dim Address() As String =
>> SelectedValue(1 ).Split((",").T oCharArray())
>> Dim Addr1 As String = Address(0).Trim
>> Dim Addr2 As String = Address(1).Trim
>> Dim City As String = Address(Address .Length - 3).Trim
>> Dim StateProvCd As String = Address(Address .Length - 2).Trim
>> Dim PostalCode As String = Address(Address .Length - 1).Trim
>>
>> Me.Addr1.Text = Name
>> Me.Addr2.Text = Addr1
>> If Not Addr2.Equals(Ci ty) Then
>> Me.Addr3.Text = Addr2
>> Me.Addr4.Text = City & " " & StateProvCd & ", " &
>> PostalCode
>> Else
>> Me.Addr3.Text = City & " " & StateProvCd & ", " &
>> PostalCode
>> End If
>> End Sub
>> End Class
>>
>> <%@ Control Language="vb" AutoEventWireup ="false"
>> Codebehind="Cus tomAddresses.as cx.vb"
>> Inherits="WBMI. Claims.CustomAd dresses"
>> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
>> <TABLE class="interior " id="Table1" width="100%">
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr1" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr2" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr3" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr4" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> </TABLE>
>>
>> Here's a sample of the webform code that calls these:
>>
>> If TypeOf
>> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> Is
>> WebControl Then
>> ControlToRender =
>> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> WebControl)
>>
>> ElseIf TypeOf
>> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
>> UserControl Then
>> ControlToRender =
>> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> UserControl)
>>
>> End If
>> NewCell.Control s.Add(ControlTo Render)
>>
>> What this boils down to is that I want to create and utilize a
>> ControlServer
>> class to encapsulate the details about how a control is created and
>> returned.
>>
>> Can this be done?
>>
>> TIA,
>> --
>> Joe
>>
>> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Dec 22 '05 #5
Joe
Hi Marina,

How would you use LoadControl from within the class that serves the
WebControls/UserControls? LoadControl must be called from a class that
inherits from the emplateControl class (i.e. Page and UserControl).

The whole point is to maximize flexibility by encapsulating the generation
of these controls, so that a webform (or another class) can simply request
the control that corresponds to an entry in the xml document.

If you know of another way to do this, please let me know. I would
appreciate any direction that you could provide.

Thanks,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
I don't think this explains why you are against using LoadControl.

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
Hi Peter,

We are using an xml document to "drive" the creation of web pages. The
document defines what controls to include on a webform and where where the
controls will appear.

I have alot of lead-way in defining how the document will be structured
and
used.

My idea was to have a class to encapsulate the generation of the required
control (be it a WebControl or a UserControl) and returns it to the
webform.
In this app, a UserControl is just a grouping of WebControls. For
example,
one UserControl (CustomAddresse s) is four textbox server controls grouped
together for name, address1, address2 and city-state-zip. This will be
used
on the page when it will display a person's addresses.

Does this help you understand hat I am really trying to do?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Peter Rilling" wrote:
Can you clarify more why you don't want to call LoadControl to load the
control. The reason LoadControl exists is so that ASP.NET has the
ability
to prepare the object has it expects such as loading the ASCX and
creating
an object model. If you create one with a constructor, then you prevent
the
engine from doing what it was suppose to.

All controls have the Render method, but you should not override that in
a
usercontrol. There are such things as custom web controls which inherit
from WebControl which you can then override the Render method.

All the HtmlTextWriter does is allow you to output the HTML. A textbox
is
nothing more than <input type="text" value="somethin g"/>.
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:0F******** *************** ***********@mic rosoft.com...
>I figured out that I have to override the Render method in the
>UserControl.
>
> I do not really understand the HtmlTextWriter. How do I write
> populated
> TextBox controls to the webform?
>
> Thank you for any available help.
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
> "Joe" wrote:
>
>> Hello All:
>>
>> Do I have to use the LoadControl method of the Page to load a
>> UserControl?
>>
>> I have a class which contains three methods (one public and two
>> private).
>> The class acts as a control server. It "serves" back the required
>> control
>> (either WebControl or UserControl) based on the contents of an xml
>> file.
>> The
>> code in the webform places each control in a TableCell.
>>
>> My problem is that the control server works as far as returning the
>> correct
>> control; but when I view the webform, the UserControl is nowhere to be
>> found.
>> It's not on the page and not in the View Source.
>>
>> Here is the server code (I'm not posting GetWebControl here):
>>
>> Public Function GetControl(ByVa l NodeToRender As XmlNode) As
>> Web.UI.Control
>> Dim ValueToMatch As String
>> If NodeToRender.Na me.Equals("Disp layText") Then
>> ValueToMatch = NodeToRender.Na me.ToLower
>> Else
>> ValueToMatch =
>> NodeToRender.At tributes("type" ).Value.ToLower
>> End If
>> Select Case ValueToMatch.To Lower
>> Case "label", "textbox", "checkbox", "displaytex t"
>> Return GetWebControl(N odeToRender)
>>
>> Case "customaddresse s"
>> Return GetUserControl( NodeToRender)
>>
>> End Select
>> End Function
>>
>> Private Function GetUserControl( ByVal NodeToRender As XmlNode) As
>> Web.UI.UserCont rol
>> Dim uControl As New CustomAddresses
>>
>> uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
>> Return uControl
>> End Function
>>
>> Here is the code and HTML for the UserControl (called
>> CustomAddresses ):
>>
>> Public Class CustomAddresses
>> Inherits System.Web.UI.U serControl
>>
>> Public Sub New()
>> Addr1 = New TextBox
>> Addr2 = New TextBox
>> Addr3 = New TextBox
>> Addr4 = New TextBox
>> End Sub
>>
>> Public Sub PopulateAddress Boxes(ByVal str As String)
>> Dim SelectedValue() As String = str.Split(("/").ToCharArray( ))
>> Dim Name As String = SelectedValue(0 ).Trim
>> Dim Address() As String =
>> SelectedValue(1 ).Split((",").T oCharArray())
>> Dim Addr1 As String = Address(0).Trim
>> Dim Addr2 As String = Address(1).Trim
>> Dim City As String = Address(Address .Length - 3).Trim
>> Dim StateProvCd As String = Address(Address .Length - 2).Trim
>> Dim PostalCode As String = Address(Address .Length - 1).Trim
>>
>> Me.Addr1.Text = Name
>> Me.Addr2.Text = Addr1
>> If Not Addr2.Equals(Ci ty) Then
>> Me.Addr3.Text = Addr2
>> Me.Addr4.Text = City & " " & StateProvCd & ", " &
>> PostalCode
>> Else
>> Me.Addr3.Text = City & " " & StateProvCd & ", " &
>> PostalCode
>> End If
>> End Sub
>> End Class
>>
>> <%@ Control Language="vb" AutoEventWireup ="false"
>> Codebehind="Cus tomAddresses.as cx.vb"
>> Inherits="WBMI. Claims.CustomAd dresses"
>> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
>> <TABLE class="interior " id="Table1" width="100%">
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr1" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr2" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr3" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> <TR>
>> <TD class="tabledat a">
>> <asp:TextBox id="Addr4" runat="server" Width="361px" ReadOnly="False "
>> MaxLength="60"> </asp:TextBox></TD>
>> </TR>
>> </TABLE>
>>
>> Here's a sample of the webform code that calls these:
>>
>> If TypeOf
>> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> Is
>> WebControl Then
>> ControlToRender =
>> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> WebControl)
>>
>> ElseIf TypeOf
>> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
>> UserControl Then
>> ControlToRender =
>> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> UserControl)
>>
>> End If
>> NewCell.Control s.Add(ControlTo Render)
>>
>> What this boils down to is that I want to create and utilize a
>> ControlServer
>> class to encapsulate the details about how a control is created and
>> returned.
>>
>> Can this be done?
>>
>> TIA,
>> --
>> Joe
>>
>> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Dec 22 '05 #6
If this is a usercontrol, nothing but another usercontrol or page can
possible do anything with it. It is a visual asp.net user control - windows
forms, etc. are not going to be able to do anything with it. Only the
ASP.NET engine can process it - which is why LoadControl was created, to do
just that. Because a constructor cannot do anything to help with rendering
it and instantiating it, and looking at the .ascx, etc etc.

So, even if you did manage to encapsulate it, only a page or usercontrol
would be able to use it anyway - so why bother?

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
Hi Marina,

How would you use LoadControl from within the class that serves the
WebControls/UserControls? LoadControl must be called from a class that
inherits from the emplateControl class (i.e. Page and UserControl).

The whole point is to maximize flexibility by encapsulating the generation
of these controls, so that a webform (or another class) can simply request
the control that corresponds to an entry in the xml document.

If you know of another way to do this, please let me know. I would
appreciate any direction that you could provide.

Thanks,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
I don't think this explains why you are against using LoadControl.

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
> Hi Peter,
>
> We are using an xml document to "drive" the creation of web pages. The
> document defines what controls to include on a webform and where where
> the
> controls will appear.
>
> I have alot of lead-way in defining how the document will be structured
> and
> used.
>
> My idea was to have a class to encapsulate the generation of the
> required
> control (be it a WebControl or a UserControl) and returns it to the
> webform.
> In this app, a UserControl is just a grouping of WebControls. For
> example,
> one UserControl (CustomAddresse s) is four textbox server controls
> grouped
> together for name, address1, address2 and city-state-zip. This will be
> used
> on the page when it will display a person's addresses.
>
> Does this help you understand hat I am really trying to do?
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
> "Peter Rilling" wrote:
>
>> Can you clarify more why you don't want to call LoadControl to load
>> the
>> control. The reason LoadControl exists is so that ASP.NET has the
>> ability
>> to prepare the object has it expects such as loading the ASCX and
>> creating
>> an object model. If you create one with a constructor, then you
>> prevent
>> the
>> engine from doing what it was suppose to.
>>
>> All controls have the Render method, but you should not override that
>> in
>> a
>> usercontrol. There are such things as custom web controls which
>> inherit
>> from WebControl which you can then override the Render method.
>>
>> All the HtmlTextWriter does is allow you to output the HTML. A
>> textbox
>> is
>> nothing more than <input type="text" value="somethin g"/>.
>>
>>
>> "Joe" <jo******@donot spam.yahoo.com> wrote in message
>> news:0F******** *************** ***********@mic rosoft.com...
>> >I figured out that I have to override the Render method in the
>> >UserControl.
>> >
>> > I do not really understand the HtmlTextWriter. How do I write
>> > populated
>> > TextBox controls to the webform?
>> >
>> > Thank you for any available help.
>> > --
>> > Joe
>> >
>> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>> >
>> >
>> > "Joe" wrote:
>> >
>> >> Hello All:
>> >>
>> >> Do I have to use the LoadControl method of the Page to load a
>> >> UserControl?
>> >>
>> >> I have a class which contains three methods (one public and two
>> >> private).
>> >> The class acts as a control server. It "serves" back the required
>> >> control
>> >> (either WebControl or UserControl) based on the contents of an xml
>> >> file.
>> >> The
>> >> code in the webform places each control in a TableCell.
>> >>
>> >> My problem is that the control server works as far as returning the
>> >> correct
>> >> control; but when I view the webform, the UserControl is nowhere to
>> >> be
>> >> found.
>> >> It's not on the page and not in the View Source.
>> >>
>> >> Here is the server code (I'm not posting GetWebControl here):
>> >>
>> >> Public Function GetControl(ByVa l NodeToRender As XmlNode) As
>> >> Web.UI.Control
>> >> Dim ValueToMatch As String
>> >> If NodeToRender.Na me.Equals("Disp layText") Then
>> >> ValueToMatch = NodeToRender.Na me.ToLower
>> >> Else
>> >> ValueToMatch =
>> >> NodeToRender.At tributes("type" ).Value.ToLower
>> >> End If
>> >> Select Case ValueToMatch.To Lower
>> >> Case "label", "textbox", "checkbox", "displaytex t"
>> >> Return GetWebControl(N odeToRender)
>> >>
>> >> Case "customaddresse s"
>> >> Return GetUserControl( NodeToRender)
>> >>
>> >> End Select
>> >> End Function
>> >>
>> >> Private Function GetUserControl( ByVal NodeToRender As XmlNode)
>> >> As
>> >> Web.UI.UserCont rol
>> >> Dim uControl As New CustomAddresses
>> >>
>> >> uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
>> >> Return uControl
>> >> End Function
>> >>
>> >> Here is the code and HTML for the UserControl (called
>> >> CustomAddresses ):
>> >>
>> >> Public Class CustomAddresses
>> >> Inherits System.Web.UI.U serControl
>> >>
>> >> Public Sub New()
>> >> Addr1 = New TextBox
>> >> Addr2 = New TextBox
>> >> Addr3 = New TextBox
>> >> Addr4 = New TextBox
>> >> End Sub
>> >>
>> >> Public Sub PopulateAddress Boxes(ByVal str As String)
>> >> Dim SelectedValue() As String =
>> >> str.Split(("/").ToCharArray( ))
>> >> Dim Name As String = SelectedValue(0 ).Trim
>> >> Dim Address() As String =
>> >> SelectedValue(1 ).Split((",").T oCharArray())
>> >> Dim Addr1 As String = Address(0).Trim
>> >> Dim Addr2 As String = Address(1).Trim
>> >> Dim City As String = Address(Address .Length - 3).Trim
>> >> Dim StateProvCd As String = Address(Address .Length -
>> >> 2).Trim
>> >> Dim PostalCode As String = Address(Address .Length - 1).Trim
>> >>
>> >> Me.Addr1.Text = Name
>> >> Me.Addr2.Text = Addr1
>> >> If Not Addr2.Equals(Ci ty) Then
>> >> Me.Addr3.Text = Addr2
>> >> Me.Addr4.Text = City & " " & StateProvCd & ", " &
>> >> PostalCode
>> >> Else
>> >> Me.Addr3.Text = City & " " & StateProvCd & ", " &
>> >> PostalCode
>> >> End If
>> >> End Sub
>> >> End Class
>> >>
>> >> <%@ Control Language="vb" AutoEventWireup ="false"
>> >> Codebehind="Cus tomAddresses.as cx.vb"
>> >> Inherits="WBMI. Claims.CustomAd dresses"
>> >> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
>> >> <TABLE class="interior " id="Table1" width="100%">
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr1" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr2" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr3" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr4" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> </TABLE>
>> >>
>> >> Here's a sample of the webform code that calls these:
>> >>
>> >> If TypeOf
>> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> >> Is
>> >> WebControl Then
>> >> ControlToRender =
>> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> WebControl)
>> >>
>> >> ElseIf TypeOf
>> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
>> >> UserControl Then
>> >> ControlToRender =
>> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> UserControl)
>> >>
>> >> End If
>> >> NewCell.Control s.Add(ControlTo Render)
>> >>
>> >> What this boils down to is that I want to create and utilize a
>> >> ControlServer
>> >> class to encapsulate the details about how a control is created and
>> >> returned.
>> >>
>> >> Can this be done?
>> >>
>> >> TIA,
>> >> --
>> >> Joe
>> >>
>> >> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>>
>>
>>


Dec 22 '05 #7
Joe
Hi Marina,

Only a Page is going to use it.

The point is to encapsulate the process of creating it. To have one class
that accepts information (in this case, an XmlNode that has data that the
class uses to return the appropriate control) and returns a control - be it a
WebControl or a UserControl. I've encapsulated the process of returning
WebControls that are then placed in the appropriate places on the Page; now I
want to encapsulate the process of returning UserControls.

Why? Because we want a central unit to handle this functionality.

Any ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
If this is a usercontrol, nothing but another usercontrol or page can
possible do anything with it. It is a visual asp.net user control - windows
forms, etc. are not going to be able to do anything with it. Only the
ASP.NET engine can process it - which is why LoadControl was created, to do
just that. Because a constructor cannot do anything to help with rendering
it and instantiating it, and looking at the .ascx, etc etc.

So, even if you did manage to encapsulate it, only a page or usercontrol
would be able to use it anyway - so why bother?

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
Hi Marina,

How would you use LoadControl from within the class that serves the
WebControls/UserControls? LoadControl must be called from a class that
inherits from the emplateControl class (i.e. Page and UserControl).

The whole point is to maximize flexibility by encapsulating the generation
of these controls, so that a webform (or another class) can simply request
the control that corresponds to an entry in the xml document.

If you know of another way to do this, please let me know. I would
appreciate any direction that you could provide.

Thanks,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
I don't think this explains why you are against using LoadControl.

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
> Hi Peter,
>
> We are using an xml document to "drive" the creation of web pages. The
> document defines what controls to include on a webform and where where
> the
> controls will appear.
>
> I have alot of lead-way in defining how the document will be structured
> and
> used.
>
> My idea was to have a class to encapsulate the generation of the
> required
> control (be it a WebControl or a UserControl) and returns it to the
> webform.
> In this app, a UserControl is just a grouping of WebControls. For
> example,
> one UserControl (CustomAddresse s) is four textbox server controls
> grouped
> together for name, address1, address2 and city-state-zip. This will be
> used
> on the page when it will display a person's addresses.
>
> Does this help you understand hat I am really trying to do?
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
> "Peter Rilling" wrote:
>
>> Can you clarify more why you don't want to call LoadControl to load
>> the
>> control. The reason LoadControl exists is so that ASP.NET has the
>> ability
>> to prepare the object has it expects such as loading the ASCX and
>> creating
>> an object model. If you create one with a constructor, then you
>> prevent
>> the
>> engine from doing what it was suppose to.
>>
>> All controls have the Render method, but you should not override that
>> in
>> a
>> usercontrol. There are such things as custom web controls which
>> inherit
>> from WebControl which you can then override the Render method.
>>
>> All the HtmlTextWriter does is allow you to output the HTML. A
>> textbox
>> is
>> nothing more than <input type="text" value="somethin g"/>.
>>
>>
>> "Joe" <jo******@donot spam.yahoo.com> wrote in message
>> news:0F******** *************** ***********@mic rosoft.com...
>> >I figured out that I have to override the Render method in the
>> >UserControl.
>> >
>> > I do not really understand the HtmlTextWriter. How do I write
>> > populated
>> > TextBox controls to the webform?
>> >
>> > Thank you for any available help.
>> > --
>> > Joe
>> >
>> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>> >
>> >
>> > "Joe" wrote:
>> >
>> >> Hello All:
>> >>
>> >> Do I have to use the LoadControl method of the Page to load a
>> >> UserControl?
>> >>
>> >> I have a class which contains three methods (one public and two
>> >> private).
>> >> The class acts as a control server. It "serves" back the required
>> >> control
>> >> (either WebControl or UserControl) based on the contents of an xml
>> >> file.
>> >> The
>> >> code in the webform places each control in a TableCell.
>> >>
>> >> My problem is that the control server works as far as returning the
>> >> correct
>> >> control; but when I view the webform, the UserControl is nowhere to
>> >> be
>> >> found.
>> >> It's not on the page and not in the View Source.
>> >>
>> >> Here is the server code (I'm not posting GetWebControl here):
>> >>
>> >> Public Function GetControl(ByVa l NodeToRender As XmlNode) As
>> >> Web.UI.Control
>> >> Dim ValueToMatch As String
>> >> If NodeToRender.Na me.Equals("Disp layText") Then
>> >> ValueToMatch = NodeToRender.Na me.ToLower
>> >> Else
>> >> ValueToMatch =
>> >> NodeToRender.At tributes("type" ).Value.ToLower
>> >> End If
>> >> Select Case ValueToMatch.To Lower
>> >> Case "label", "textbox", "checkbox", "displaytex t"
>> >> Return GetWebControl(N odeToRender)
>> >>
>> >> Case "customaddresse s"
>> >> Return GetUserControl( NodeToRender)
>> >>
>> >> End Select
>> >> End Function
>> >>
>> >> Private Function GetUserControl( ByVal NodeToRender As XmlNode)
>> >> As
>> >> Web.UI.UserCont rol
>> >> Dim uControl As New CustomAddresses
>> >>
>> >> uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
>> >> Return uControl
>> >> End Function
>> >>
>> >> Here is the code and HTML for the UserControl (called
>> >> CustomAddresses ):
>> >>
>> >> Public Class CustomAddresses
>> >> Inherits System.Web.UI.U serControl
>> >>
>> >> Public Sub New()
>> >> Addr1 = New TextBox
>> >> Addr2 = New TextBox
>> >> Addr3 = New TextBox
>> >> Addr4 = New TextBox
>> >> End Sub
>> >>
>> >> Public Sub PopulateAddress Boxes(ByVal str As String)
>> >> Dim SelectedValue() As String =
>> >> str.Split(("/").ToCharArray( ))
>> >> Dim Name As String = SelectedValue(0 ).Trim
>> >> Dim Address() As String =
>> >> SelectedValue(1 ).Split((",").T oCharArray())
>> >> Dim Addr1 As String = Address(0).Trim
>> >> Dim Addr2 As String = Address(1).Trim
>> >> Dim City As String = Address(Address .Length - 3).Trim
>> >> Dim StateProvCd As String = Address(Address .Length -
>> >> 2).Trim
>> >> Dim PostalCode As String = Address(Address .Length - 1).Trim
>> >>
>> >> Me.Addr1.Text = Name
>> >> Me.Addr2.Text = Addr1
>> >> If Not Addr2.Equals(Ci ty) Then
>> >> Me.Addr3.Text = Addr2
>> >> Me.Addr4.Text = City & " " & StateProvCd & ", " &
>> >> PostalCode
>> >> Else
>> >> Me.Addr3.Text = City & " " & StateProvCd & ", " &
>> >> PostalCode
>> >> End If
>> >> End Sub
>> >> End Class
>> >>
>> >> <%@ Control Language="vb" AutoEventWireup ="false"
>> >> Codebehind="Cus tomAddresses.as cx.vb"
>> >> Inherits="WBMI. Claims.CustomAd dresses"
>> >> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
>> >> <TABLE class="interior " id="Table1" width="100%">
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr1" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr2" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr3" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> <TR>
>> >> <TD class="tabledat a">
>> >> <asp:TextBox id="Addr4" runat="server" Width="361px"
>> >> ReadOnly="False "
>> >> MaxLength="60"> </asp:TextBox></TD>
>> >> </TR>
>> >> </TABLE>
>> >>
>> >> Here's a sample of the webform code that calls these:
>> >>
>> >> If TypeOf
>> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> >> Is
>> >> WebControl Then
>> >> ControlToRender =
>> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> WebControl)
>> >>
>> >> ElseIf TypeOf
>> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e)) Is
>> >> UserControl Then
>> >> ControlToRender =
>> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> UserControl)
>> >>
>> >> End If
>> >> NewCell.Control s.Add(ControlTo Render)
>> >>
>> >> What this boils down to is that I want to create and utilize a
>> >> ControlServer
>> >> class to encapsulate the details about how a control is created and
>> >> returned.
>> >>
>> >> Can this be done?
>> >>
>> >> TIA,
>> >> --
>> >> Joe
>> >>
>> >> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>>
>>
>>


Dec 22 '05 #8
That's fine. But why can't this unit use LoadControl? That is really the
question.

There are many way to accomplish this central place having access to
whatever page wants the user control created, so it can use the page's
LoadControl.

I think you are getting stuck in trying to box everything up, and not really
thinking about the functionality here. Only a Page can host a user control.
Only ASP.NET's engine can parse the .ascx, turn it into an object, use the
class behind it to render it all. So, whatever black box is going to have
this functionality, is going to need to have access to a Page on way or
another. It could be through inheritance, it could be through passing the
Page instance up, etc.

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:73******** *************** ***********@mic rosoft.com...
Hi Marina,

Only a Page is going to use it.

The point is to encapsulate the process of creating it. To have one class
that accepts information (in this case, an XmlNode that has data that the
class uses to return the appropriate control) and returns a control - be
it a
WebControl or a UserControl. I've encapsulated the process of returning
WebControls that are then placed in the appropriate places on the Page;
now I
want to encapsulate the process of returning UserControls.

Why? Because we want a central unit to handle this functionality.

Any ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
If this is a usercontrol, nothing but another usercontrol or page can
possible do anything with it. It is a visual asp.net user control -
windows
forms, etc. are not going to be able to do anything with it. Only the
ASP.NET engine can process it - which is why LoadControl was created, to
do
just that. Because a constructor cannot do anything to help with
rendering
it and instantiating it, and looking at the .ascx, etc etc.

So, even if you did manage to encapsulate it, only a page or usercontrol
would be able to use it anyway - so why bother?

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
> Hi Marina,
>
> How would you use LoadControl from within the class that serves the
> WebControls/UserControls? LoadControl must be called from a class that
> inherits from the emplateControl class (i.e. Page and UserControl).
>
> The whole point is to maximize flexibility by encapsulating the
> generation
> of these controls, so that a webform (or another class) can simply
> request
> the control that corresponds to an entry in the xml document.
>
> If you know of another way to do this, please let me know. I would
> appreciate any direction that you could provide.
>
> Thanks,
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
> "Marina" wrote:
>
>> I don't think this explains why you are against using LoadControl.
>>
>> "Joe" <jo******@donot spam.yahoo.com> wrote in message
>> news:14******** *************** ***********@mic rosoft.com...
>> > Hi Peter,
>> >
>> > We are using an xml document to "drive" the creation of web pages.
>> > The
>> > document defines what controls to include on a webform and where
>> > where
>> > the
>> > controls will appear.
>> >
>> > I have alot of lead-way in defining how the document will be
>> > structured
>> > and
>> > used.
>> >
>> > My idea was to have a class to encapsulate the generation of the
>> > required
>> > control (be it a WebControl or a UserControl) and returns it to the
>> > webform.
>> > In this app, a UserControl is just a grouping of WebControls. For
>> > example,
>> > one UserControl (CustomAddresse s) is four textbox server controls
>> > grouped
>> > together for name, address1, address2 and city-state-zip. This will
>> > be
>> > used
>> > on the page when it will display a person's addresses.
>> >
>> > Does this help you understand hat I am really trying to do?
>> > --
>> > Joe
>> >
>> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>> >
>> >
>> > "Peter Rilling" wrote:
>> >
>> >> Can you clarify more why you don't want to call LoadControl to load
>> >> the
>> >> control. The reason LoadControl exists is so that ASP.NET has the
>> >> ability
>> >> to prepare the object has it expects such as loading the ASCX and
>> >> creating
>> >> an object model. If you create one with a constructor, then you
>> >> prevent
>> >> the
>> >> engine from doing what it was suppose to.
>> >>
>> >> All controls have the Render method, but you should not override
>> >> that
>> >> in
>> >> a
>> >> usercontrol. There are such things as custom web controls which
>> >> inherit
>> >> from WebControl which you can then override the Render method.
>> >>
>> >> All the HtmlTextWriter does is allow you to output the HTML. A
>> >> textbox
>> >> is
>> >> nothing more than <input type="text" value="somethin g"/>.
>> >>
>> >>
>> >> "Joe" <jo******@donot spam.yahoo.com> wrote in message
>> >> news:0F******** *************** ***********@mic rosoft.com...
>> >> >I figured out that I have to override the Render method in the
>> >> >UserControl.
>> >> >
>> >> > I do not really understand the HtmlTextWriter. How do I write
>> >> > populated
>> >> > TextBox controls to the webform?
>> >> >
>> >> > Thank you for any available help.
>> >> > --
>> >> > Joe
>> >> >
>> >> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA
>> >> > Automation
>> >> >
>> >> >
>> >> > "Joe" wrote:
>> >> >
>> >> >> Hello All:
>> >> >>
>> >> >> Do I have to use the LoadControl method of the Page to load a
>> >> >> UserControl?
>> >> >>
>> >> >> I have a class which contains three methods (one public and two
>> >> >> private).
>> >> >> The class acts as a control server. It "serves" back the
>> >> >> required
>> >> >> control
>> >> >> (either WebControl or UserControl) based on the contents of an
>> >> >> xml
>> >> >> file.
>> >> >> The
>> >> >> code in the webform places each control in a TableCell.
>> >> >>
>> >> >> My problem is that the control server works as far as returning
>> >> >> the
>> >> >> correct
>> >> >> control; but when I view the webform, the UserControl is nowhere
>> >> >> to
>> >> >> be
>> >> >> found.
>> >> >> It's not on the page and not in the View Source.
>> >> >>
>> >> >> Here is the server code (I'm not posting GetWebControl here):
>> >> >>
>> >> >> Public Function GetControl(ByVa l NodeToRender As XmlNode) As
>> >> >> Web.UI.Control
>> >> >> Dim ValueToMatch As String
>> >> >> If NodeToRender.Na me.Equals("Disp layText") Then
>> >> >> ValueToMatch = NodeToRender.Na me.ToLower
>> >> >> Else
>> >> >> ValueToMatch =
>> >> >> NodeToRender.At tributes("type" ).Value.ToLower
>> >> >> End If
>> >> >> Select Case ValueToMatch.To Lower
>> >> >> Case "label", "textbox", "checkbox", "displaytex t"
>> >> >> Return GetWebControl(N odeToRender)
>> >> >>
>> >> >> Case "customaddresse s"
>> >> >> Return GetUserControl( NodeToRender)
>> >> >>
>> >> >> End Select
>> >> >> End Function
>> >> >>
>> >> >> Private Function GetUserControl( ByVal NodeToRender As
>> >> >> XmlNode)
>> >> >> As
>> >> >> Web.UI.UserCont rol
>> >> >> Dim uControl As New CustomAddresses
>> >> >>
>> >> >> uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
>> >> >> Return uControl
>> >> >> End Function
>> >> >>
>> >> >> Here is the code and HTML for the UserControl (called
>> >> >> CustomAddresses ):
>> >> >>
>> >> >> Public Class CustomAddresses
>> >> >> Inherits System.Web.UI.U serControl
>> >> >>
>> >> >> Public Sub New()
>> >> >> Addr1 = New TextBox
>> >> >> Addr2 = New TextBox
>> >> >> Addr3 = New TextBox
>> >> >> Addr4 = New TextBox
>> >> >> End Sub
>> >> >>
>> >> >> Public Sub PopulateAddress Boxes(ByVal str As String)
>> >> >> Dim SelectedValue() As String =
>> >> >> str.Split(("/").ToCharArray( ))
>> >> >> Dim Name As String = SelectedValue(0 ).Trim
>> >> >> Dim Address() As String =
>> >> >> SelectedValue(1 ).Split((",").T oCharArray())
>> >> >> Dim Addr1 As String = Address(0).Trim
>> >> >> Dim Addr2 As String = Address(1).Trim
>> >> >> Dim City As String = Address(Address .Length - 3).Trim
>> >> >> Dim StateProvCd As String = Address(Address .Length -
>> >> >> 2).Trim
>> >> >> Dim PostalCode As String = Address(Address .Length -
>> >> >> 1).Trim
>> >> >>
>> >> >> Me.Addr1.Text = Name
>> >> >> Me.Addr2.Text = Addr1
>> >> >> If Not Addr2.Equals(Ci ty) Then
>> >> >> Me.Addr3.Text = Addr2
>> >> >> Me.Addr4.Text = City & " " & StateProvCd & ", " &
>> >> >> PostalCode
>> >> >> Else
>> >> >> Me.Addr3.Text = City & " " & StateProvCd & ", " &
>> >> >> PostalCode
>> >> >> End If
>> >> >> End Sub
>> >> >> End Class
>> >> >>
>> >> >> <%@ Control Language="vb" AutoEventWireup ="false"
>> >> >> Codebehind="Cus tomAddresses.as cx.vb"
>> >> >> Inherits="WBMI. Claims.CustomAd dresses"
>> >> >> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
>> >> >> <TABLE class="interior " id="Table1" width="100%">
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr1" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr2" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr3" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr4" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> </TABLE>
>> >> >>
>> >> >> Here's a sample of the webform code that calls these:
>> >> >>
>> >> >> If TypeOf
>> >> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> >> >> Is
>> >> >> WebControl Then
>> >> >> ControlToRender =
>> >> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> >> WebControl)
>> >> >>
>> >> >> ElseIf TypeOf
>> >> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> >> >> Is
>> >> >> UserControl Then
>> >> >> ControlToRender =
>> >> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> >> UserControl)
>> >> >>
>> >> >> End If
>> >> >> NewCell.Control s.Add(ControlTo Render)
>> >> >>
>> >> >> What this boils down to is that I want to create and utilize a
>> >> >> ControlServer
>> >> >> class to encapsulate the details about how a control is created
>> >> >> and
>> >> >> returned.
>> >> >>
>> >> >> Can this be done?
>> >> >>
>> >> >> TIA,
>> >> >> --
>> >> >> Joe
>> >> >>
>> >> >> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA
>> >> >> Automation
>> >>
>> >>
>> >>
>>
>>
>>


Dec 22 '05 #9
Joe
It can use LoadControl; in fact, I want to use LoadControl because I don't
want to bother overriding the Render method of the UserControl. The problem
is that I didn't have access to LoadControl from within my class (let's call
it ControlServer). So I instantiate and call ControlServer class from within
the Page (I am doing this now).

How would you pass a Page Instance up? Like so?

Dim sC as New ControlServer
sC.SomeMethod(M e, another_data_va lue)

--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
That's fine. But why can't this unit use LoadControl? That is really the
question.

There are many way to accomplish this central place having access to
whatever page wants the user control created, so it can use the page's
LoadControl.

I think you are getting stuck in trying to box everything up, and not really
thinking about the functionality here. Only a Page can host a user control.
Only ASP.NET's engine can parse the .ascx, turn it into an object, use the
class behind it to render it all. So, whatever black box is going to have
this functionality, is going to need to have access to a Page on way or
another. It could be through inheritance, it could be through passing the
Page instance up, etc.

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:73******** *************** ***********@mic rosoft.com...
Hi Marina,

Only a Page is going to use it.

The point is to encapsulate the process of creating it. To have one class
that accepts information (in this case, an XmlNode that has data that the
class uses to return the appropriate control) and returns a control - be
it a
WebControl or a UserControl. I've encapsulated the process of returning
WebControls that are then placed in the appropriate places on the Page;
now I
want to encapsulate the process of returning UserControls.

Why? Because we want a central unit to handle this functionality.

Any ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Marina" wrote:
If this is a usercontrol, nothing but another usercontrol or page can
possible do anything with it. It is a visual asp.net user control -
windows
forms, etc. are not going to be able to do anything with it. Only the
ASP.NET engine can process it - which is why LoadControl was created, to
do
just that. Because a constructor cannot do anything to help with
rendering
it and instantiating it, and looking at the .ascx, etc etc.

So, even if you did manage to encapsulate it, only a page or usercontrol
would be able to use it anyway - so why bother?

"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
> Hi Marina,
>
> How would you use LoadControl from within the class that serves the
> WebControls/UserControls? LoadControl must be called from a class that
> inherits from the emplateControl class (i.e. Page and UserControl).
>
> The whole point is to maximize flexibility by encapsulating the
> generation
> of these controls, so that a webform (or another class) can simply
> request
> the control that corresponds to an entry in the xml document.
>
> If you know of another way to do this, please let me know. I would
> appreciate any direction that you could provide.
>
> Thanks,
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
> "Marina" wrote:
>
>> I don't think this explains why you are against using LoadControl.
>>
>> "Joe" <jo******@donot spam.yahoo.com> wrote in message
>> news:14******** *************** ***********@mic rosoft.com...
>> > Hi Peter,
>> >
>> > We are using an xml document to "drive" the creation of web pages.
>> > The
>> > document defines what controls to include on a webform and where
>> > where
>> > the
>> > controls will appear.
>> >
>> > I have alot of lead-way in defining how the document will be
>> > structured
>> > and
>> > used.
>> >
>> > My idea was to have a class to encapsulate the generation of the
>> > required
>> > control (be it a WebControl or a UserControl) and returns it to the
>> > webform.
>> > In this app, a UserControl is just a grouping of WebControls. For
>> > example,
>> > one UserControl (CustomAddresse s) is four textbox server controls
>> > grouped
>> > together for name, address1, address2 and city-state-zip. This will
>> > be
>> > used
>> > on the page when it will display a person's addresses.
>> >
>> > Does this help you understand hat I am really trying to do?
>> > --
>> > Joe
>> >
>> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>> >
>> >
>> > "Peter Rilling" wrote:
>> >
>> >> Can you clarify more why you don't want to call LoadControl to load
>> >> the
>> >> control. The reason LoadControl exists is so that ASP.NET has the
>> >> ability
>> >> to prepare the object has it expects such as loading the ASCX and
>> >> creating
>> >> an object model. If you create one with a constructor, then you
>> >> prevent
>> >> the
>> >> engine from doing what it was suppose to.
>> >>
>> >> All controls have the Render method, but you should not override
>> >> that
>> >> in
>> >> a
>> >> usercontrol. There are such things as custom web controls which
>> >> inherit
>> >> from WebControl which you can then override the Render method.
>> >>
>> >> All the HtmlTextWriter does is allow you to output the HTML. A
>> >> textbox
>> >> is
>> >> nothing more than <input type="text" value="somethin g"/>.
>> >>
>> >>
>> >> "Joe" <jo******@donot spam.yahoo.com> wrote in message
>> >> news:0F******** *************** ***********@mic rosoft.com...
>> >> >I figured out that I have to override the Render method in the
>> >> >UserControl.
>> >> >
>> >> > I do not really understand the HtmlTextWriter. How do I write
>> >> > populated
>> >> > TextBox controls to the webform?
>> >> >
>> >> > Thank you for any available help.
>> >> > --
>> >> > Joe
>> >> >
>> >> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA
>> >> > Automation
>> >> >
>> >> >
>> >> > "Joe" wrote:
>> >> >
>> >> >> Hello All:
>> >> >>
>> >> >> Do I have to use the LoadControl method of the Page to load a
>> >> >> UserControl?
>> >> >>
>> >> >> I have a class which contains three methods (one public and two
>> >> >> private).
>> >> >> The class acts as a control server. It "serves" back the
>> >> >> required
>> >> >> control
>> >> >> (either WebControl or UserControl) based on the contents of an
>> >> >> xml
>> >> >> file.
>> >> >> The
>> >> >> code in the webform places each control in a TableCell.
>> >> >>
>> >> >> My problem is that the control server works as far as returning
>> >> >> the
>> >> >> correct
>> >> >> control; but when I view the webform, the UserControl is nowhere
>> >> >> to
>> >> >> be
>> >> >> found.
>> >> >> It's not on the page and not in the View Source.
>> >> >>
>> >> >> Here is the server code (I'm not posting GetWebControl here):
>> >> >>
>> >> >> Public Function GetControl(ByVa l NodeToRender As XmlNode) As
>> >> >> Web.UI.Control
>> >> >> Dim ValueToMatch As String
>> >> >> If NodeToRender.Na me.Equals("Disp layText") Then
>> >> >> ValueToMatch = NodeToRender.Na me.ToLower
>> >> >> Else
>> >> >> ValueToMatch =
>> >> >> NodeToRender.At tributes("type" ).Value.ToLower
>> >> >> End If
>> >> >> Select Case ValueToMatch.To Lower
>> >> >> Case "label", "textbox", "checkbox", "displaytex t"
>> >> >> Return GetWebControl(N odeToRender)
>> >> >>
>> >> >> Case "customaddresse s"
>> >> >> Return GetUserControl( NodeToRender)
>> >> >>
>> >> >> End Select
>> >> >> End Function
>> >> >>
>> >> >> Private Function GetUserControl( ByVal NodeToRender As
>> >> >> XmlNode)
>> >> >> As
>> >> >> Web.UI.UserCont rol
>> >> >> Dim uControl As New CustomAddresses
>> >> >>
>> >> >> uControl.Popula teAddressBoxes( NodeToRender.At tributes("value ").Value.Tr im)
>> >> >> Return uControl
>> >> >> End Function
>> >> >>
>> >> >> Here is the code and HTML for the UserControl (called
>> >> >> CustomAddresses ):
>> >> >>
>> >> >> Public Class CustomAddresses
>> >> >> Inherits System.Web.UI.U serControl
>> >> >>
>> >> >> Public Sub New()
>> >> >> Addr1 = New TextBox
>> >> >> Addr2 = New TextBox
>> >> >> Addr3 = New TextBox
>> >> >> Addr4 = New TextBox
>> >> >> End Sub
>> >> >>
>> >> >> Public Sub PopulateAddress Boxes(ByVal str As String)
>> >> >> Dim SelectedValue() As String =
>> >> >> str.Split(("/").ToCharArray( ))
>> >> >> Dim Name As String = SelectedValue(0 ).Trim
>> >> >> Dim Address() As String =
>> >> >> SelectedValue(1 ).Split((",").T oCharArray())
>> >> >> Dim Addr1 As String = Address(0).Trim
>> >> >> Dim Addr2 As String = Address(1).Trim
>> >> >> Dim City As String = Address(Address .Length - 3).Trim
>> >> >> Dim StateProvCd As String = Address(Address .Length -
>> >> >> 2).Trim
>> >> >> Dim PostalCode As String = Address(Address .Length -
>> >> >> 1).Trim
>> >> >>
>> >> >> Me.Addr1.Text = Name
>> >> >> Me.Addr2.Text = Addr1
>> >> >> If Not Addr2.Equals(Ci ty) Then
>> >> >> Me.Addr3.Text = Addr2
>> >> >> Me.Addr4.Text = City & " " & StateProvCd & ", " &
>> >> >> PostalCode
>> >> >> Else
>> >> >> Me.Addr3.Text = City & " " & StateProvCd & ", " &
>> >> >> PostalCode
>> >> >> End If
>> >> >> End Sub
>> >> >> End Class
>> >> >>
>> >> >> <%@ Control Language="vb" AutoEventWireup ="false"
>> >> >> Codebehind="Cus tomAddresses.as cx.vb"
>> >> >> Inherits="WBMI. Claims.CustomAd dresses"
>> >> >> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
>> >> >> <TABLE class="interior " id="Table1" width="100%">
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr1" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr2" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr3" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> <TR>
>> >> >> <TD class="tabledat a">
>> >> >> <asp:TextBox id="Addr4" runat="server" Width="361px"
>> >> >> ReadOnly="False "
>> >> >> MaxLength="60"> </asp:TextBox></TD>
>> >> >> </TR>
>> >> >> </TABLE>
>> >> >>
>> >> >> Here's a sample of the webform code that calls these:
>> >> >>
>> >> >> If TypeOf
>> >> >> SvrControl.GetC ontrol(m_FormTe mplate.GetContr olNode(ChildNod e))
>> >> >> Is
>> >> >> WebControl Then
>> >> >> ControlToRender =
>> >> >> CType(SvrContro l.GetControl(m_ FormTemplate.Ge tControlNode(Ch ildNode)),
>> >> >> WebControl)

Dec 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9319
by: Dennis Burdett | last post by:
I have a pretty complex control which use to be a C# windows form that I am trying to make into a control that can be dragged onto a VB6 form. I was able to make it into a com class that I could then go to VB6 and add the reference and call the object there without any problems. When I try to make it into a UserControl, I get it to build and it registers itself during the build with no errors BUT I can not add the dll to the vb6...
4
6958
by: John | last post by:
Hi all, I'm having a little problem understanding the concepts of dynamically loading/unloading user conrols: 1. If I have a couple of usercontrols embedded within a few tables cells on my page, setting the usercontrol's visible to false still fires the Page_Load event. Isn't this unnecessary overhead when it doesn't even show in my page.
1
1468
by: Sundaresan | last post by:
I've a form where I load two user controls dynamically. User Control-1 has a no.of dropdowns and based on the selection I typically populate a datagrid in the user control-2, Also the I could be loading a different usercontrol-2 based on the selections in usercontrol-1. Also I thought of passing the selection values through
2
2460
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@ Control Language="c#" className="Disable1" src="Disable.ascx.cs" %> The host page for this control is named UserControl.aspx. The first 2 lines are: <%@ Reference control="Disable.ascx" %>
0
1518
by: Phl | last post by:
Hi, I am trying to create an webform which loads usercontrols dyanamically. I know exactly what to load for some of these controls but for some, I dont want to load it until the user has press a button. The controls which I know I will need at page init gets their viewstate contents back properly per postback. However I am having a lot of troubles with keeping the contents of usercontrols which are
1
1114
by: Sridhar | last post by:
Hi, I have created a webpage. In that webpage I am loading a user control into a place holder. The user control has a link button in it. when I click on that I need to able to load another user control in place of this into a place holder. I am not knowing how to do that. Could you please let me know. Or if my design of using user controls in this case is wrong please let me know the solution so that I could change it. Thanks,
4
1633
by: Tim B | last post by:
Hi, Previously I was loading my .NET Usercontrol like this : <OBJECT id="Obj" classid="Viewer.dll#Viewer.Viewer" width=105 height=20 VIEWASTEXT><param name="DONOTHING" value="1"> </OBJECT> Everything was working great until the new patch came out and changed the way the ActiveX / Usercontrols are loaded.
0
1589
by: Mark | last post by:
I am converting a VB6/COM application to VB.NET and must remove all COM objects. VB6/COM App Architecture: Windows Form hosts WebBrowser which loads HTML snippets from local disk. Some of the HTML snippets contain <objecttags for ActiveX Control. ActiveX Control loads and works without issue. VB.NET App Architecture: SAME as above except for: The WebBrowser Control is initially seeded by loading HTML from local disk. All Other
1
1755
by: Nathan Sokalski | last post by:
I am revieving the following error for one of my controls when loading any pages that use it: Server Error in '/exposure/app' Application. -------------------------------------------------------------------------------- Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
0
9942
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10848
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10417
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9575
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7972
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5798
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3234
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.