R
Robert Bull
I have created a web control library that contains a text box and a
search button that I plan on using multiple times. The functionality
of the control works fine. I can add the .dll to the toolbox and add
multiple instances of the control on the form, but the controls are
added as if the web form is in a flow layout. It only seems to be
happening with the custom contol because I can add buttons and they
render where I draw them. The following code is the html that creates
the custom control:
<cc2:ctlSearch id="CtlSearch1" style="Z-INDEX: 101; LEFT: 15px;
POSITION:absolute; TOP: 11px" runat="server"></cc2:ctlSearch></DIV>
<cc2:ctlSearch id="CtlSearch2" style="Z-INDEX: 101; LEFT: 104px;
POSITION: absolute; TOP: 421px" runat="server" Width="223px"
Height="22px"></cc2:ctlSearch>
The 'POSITION: absolute' should take care of this...shouldn't it? It
allows me to draw the control wherever I want in design mode but when
I view in the browser, it always renders at the top left corner of the
screen, stacked on top of each other. I override the render sub
routine in the web control library. Could this be the problem? I have
added the code to the web control library below. Thanks in advance
-Rob
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Drawing
<DefaultProperty("Text"), ToolboxData("<{0}:ctlSearch
runat=server></{0}:ctlSearch>")> _
Public Class ctlSearch
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim _text As String
Protected WithEvents ddlSearchType As DropDownList
Protected WithEvents txtSearchCriteria As TextBox
Protected WithEvents lblSearchType As Label
Protected WithEvents lblSearchCriteria As Label
Protected WithEvents btnSearch As Button
<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.WriteFullBeginTag("Table")
output.WriteFullBeginTag("TR") 'Row 1 begin
output.WriteFullBeginTag("TD")
lblSearchType.RenderControl(output)
output.WriteEndTag("TD")
output.WriteFullBeginTag("TD")
ddlSearchType.RenderControl(output)
output.WriteEndTag("TD")
output.WriteFullBeginTag("TD")
txtSearchCriteria.RenderControl(output)
output.WriteEndTag("TD")
output.WriteFullBeginTag("TD")
btnSearch.RenderControl(output)
output.WriteEndTag("TD")
output.WriteEndTag("TR") 'Row 1 End
output.WriteEndTag("TABLE")
output.Flush()
End Sub
Protected Overrides Sub CreateChildControls()
'drop down list
ddlSearchType = New DropDownList
With ddlSearchType
.ID = "ddlSearchType"
.Width = Unit.Pixel(75)
.Items.Add("SSN")
.Items.Add("EMP#")
End With
'List Label
lblSearchType = New Label
With lblSearchType
.ID = "lblSearchType"
.Text = "Search Type: "
End With
'Criteria text box
txtSearchCriteria = New TextBox
With txtSearchCriteria
.ID = "txtSearchCriteria"
.Width = Unit.Pixel(150)
End With
'Criteria label
lblSearchCriteria = New Label
With lblSearchCriteria
.ID = "lblSearchCriteria"
End With
'Search Button
btnSearch = New Button
With btnSearch
.ID = "btnSearch"
.Text = "Search"
End With
'Add to the collection
Me.Controls.Add(lblSearchType)
Me.Controls.Add(ddlSearchType)
Me.Controls.Add(lblSearchCriteria)
Me.Controls.Add(txtSearchCriteria)
Me.Controls.Add(btnSearch)
End Sub
Public Sub New()
MyBase.New()
End Sub
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
'Me.txtSearchCriteria.Text = "Hello World"
End Sub
End Class
search button that I plan on using multiple times. The functionality
of the control works fine. I can add the .dll to the toolbox and add
multiple instances of the control on the form, but the controls are
added as if the web form is in a flow layout. It only seems to be
happening with the custom contol because I can add buttons and they
render where I draw them. The following code is the html that creates
the custom control:
<cc2:ctlSearch id="CtlSearch1" style="Z-INDEX: 101; LEFT: 15px;
POSITION:absolute; TOP: 11px" runat="server"></cc2:ctlSearch></DIV>
<cc2:ctlSearch id="CtlSearch2" style="Z-INDEX: 101; LEFT: 104px;
POSITION: absolute; TOP: 421px" runat="server" Width="223px"
Height="22px"></cc2:ctlSearch>
The 'POSITION: absolute' should take care of this...shouldn't it? It
allows me to draw the control wherever I want in design mode but when
I view in the browser, it always renders at the top left corner of the
screen, stacked on top of each other. I override the render sub
routine in the web control library. Could this be the problem? I have
added the code to the web control library below. Thanks in advance
-Rob
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Drawing
<DefaultProperty("Text"), ToolboxData("<{0}:ctlSearch
runat=server></{0}:ctlSearch>")> _
Public Class ctlSearch
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim _text As String
Protected WithEvents ddlSearchType As DropDownList
Protected WithEvents txtSearchCriteria As TextBox
Protected WithEvents lblSearchType As Label
Protected WithEvents lblSearchCriteria As Label
Protected WithEvents btnSearch As Button
<Bindable(True), Category("Appearance"), DefaultValue("")>
Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.WriteFullBeginTag("Table")
output.WriteFullBeginTag("TR") 'Row 1 begin
output.WriteFullBeginTag("TD")
lblSearchType.RenderControl(output)
output.WriteEndTag("TD")
output.WriteFullBeginTag("TD")
ddlSearchType.RenderControl(output)
output.WriteEndTag("TD")
output.WriteFullBeginTag("TD")
txtSearchCriteria.RenderControl(output)
output.WriteEndTag("TD")
output.WriteFullBeginTag("TD")
btnSearch.RenderControl(output)
output.WriteEndTag("TD")
output.WriteEndTag("TR") 'Row 1 End
output.WriteEndTag("TABLE")
output.Flush()
End Sub
Protected Overrides Sub CreateChildControls()
'drop down list
ddlSearchType = New DropDownList
With ddlSearchType
.ID = "ddlSearchType"
.Width = Unit.Pixel(75)
.Items.Add("SSN")
.Items.Add("EMP#")
End With
'List Label
lblSearchType = New Label
With lblSearchType
.ID = "lblSearchType"
.Text = "Search Type: "
End With
'Criteria text box
txtSearchCriteria = New TextBox
With txtSearchCriteria
.ID = "txtSearchCriteria"
.Width = Unit.Pixel(150)
End With
'Criteria label
lblSearchCriteria = New Label
With lblSearchCriteria
.ID = "lblSearchCriteria"
End With
'Search Button
btnSearch = New Button
With btnSearch
.ID = "btnSearch"
.Text = "Search"
End With
'Add to the collection
Me.Controls.Add(lblSearchType)
Me.Controls.Add(ddlSearchType)
Me.Controls.Add(lblSearchCriteria)
Me.Controls.Add(txtSearchCriteria)
Me.Controls.Add(btnSearch)
End Sub
Public Sub New()
MyBase.New()
End Sub
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
'Me.txtSearchCriteria.Text = "Hello World"
End Sub
End Class