473,394 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Hosting controls in a custom server control

Hi,

I am trying to create a custom server control that contains several
dropdownlists. The control looks like this:

Dim pnlHeader As New Panel

Protected Overrides Sub RenderContents(ByVal writer as HtmlTextWriter)
pnlHeader.RenderControl(writer)
End Sub

Public Sub Setup_Control()
Dim table As New HtmlControls.HtmlTable
table.Attributes.Add("style", "width:100%")
pnlHeader.Controls.Add(table)

Dim row As New HtmlControls.HtmlTableRow

Dim cellLabel As New HtmlControls.HtmlTableCell
cellLabel.Width = "60%"
Dim lblProblems As New Label
lblProblems.ID = "lbl" & Category.ProblemTypeId
lblProblems.Text = "Choose Vendor for All " &
Category.ProblemType & " Problems."
cellLabel.Controls.Add(lblProblems)

Dim cellDDL As New HtmlControls.HtmlTableCell
cellDDL.Width = "30%"
Dim ddlAll As New DropDownList
ddlAll.ID = "ddlVendorForAll" &
Category.ProblemTypeId.ToString()
ddlAll.AutoPostBack = True
Common.FillList(ddlAll, HeatMapData.GetVendors(PropertyId,
"[Choose a Vendor]"))
cellDDL.Controls.Add(ddlAll)
listDDL.Add(ddlAll)
AddHandler ddlAll.SelectedIndexChanged, AddressOf
ddlAll_SelectedIndexChanged

Dim cellImage As New HtmlControls.HtmlTableCell
cellImage.Width = "9%"
Dim imgExpand As New WebControls.Image
imgExpand.ID = "imgExpand" &
Category.ProblemTypeId.ToString()
imgExpand.ImageUrl = "~/images/icons/118.png"
imgExpand.ToolTip = "View Details"
Dim imgCollapse As New WebControls.Image
imgCollapse.ID = "imgCollapse" &
Category.ProblemTypeId.ToString()
imgCollapse.ImageUrl = "~/images/icons/116.png"
imgCollapse.ToolTip = "Hide Details"
imgCollapse.Attributes.Add("style", "display:none")

cellImage.Controls.Add(imgExpand)
cellImage.Controls.Add(imgCollapse)

row.Controls.Add(cellLabel)
row.Controls.Add(cellDDL)
row.Controls.Add(cellImage)
table.Rows.Add(row)

pnlHeader.BackColor = Drawing.Color.FromArgb(255, 206,
204, 204)
End Sub

Protected Sub ddlAll_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub
The control renders fine. The problem I am having is that the
dynamically created dropdownlist (ddlAll) does not fire the
SelectedIndexChanged event. What am I missing?

Thanks,
Jeremy
Mar 17 '08 #1
5 1401
when do you call Setup_Control() (and why do you have it?). it must be called
in oninit of the page, or better yet, change it to CreateChildControls.
-- bruce (sqlwork.com)
"jb*****@gmail.com" wrote:
Hi,

I am trying to create a custom server control that contains several
dropdownlists. The control looks like this:

Dim pnlHeader As New Panel

Protected Overrides Sub RenderContents(ByVal writer as HtmlTextWriter)
pnlHeader.RenderControl(writer)
End Sub

Public Sub Setup_Control()
Dim table As New HtmlControls.HtmlTable
table.Attributes.Add("style", "width:100%")
pnlHeader.Controls.Add(table)

Dim row As New HtmlControls.HtmlTableRow

Dim cellLabel As New HtmlControls.HtmlTableCell
cellLabel.Width = "60%"
Dim lblProblems As New Label
lblProblems.ID = "lbl" & Category.ProblemTypeId
lblProblems.Text = "Choose Vendor for All " &
Category.ProblemType & " Problems."
cellLabel.Controls.Add(lblProblems)

Dim cellDDL As New HtmlControls.HtmlTableCell
cellDDL.Width = "30%"
Dim ddlAll As New DropDownList
ddlAll.ID = "ddlVendorForAll" &
Category.ProblemTypeId.ToString()
ddlAll.AutoPostBack = True
Common.FillList(ddlAll, HeatMapData.GetVendors(PropertyId,
"[Choose a Vendor]"))
cellDDL.Controls.Add(ddlAll)
listDDL.Add(ddlAll)
AddHandler ddlAll.SelectedIndexChanged, AddressOf
ddlAll_SelectedIndexChanged

Dim cellImage As New HtmlControls.HtmlTableCell
cellImage.Width = "9%"
Dim imgExpand As New WebControls.Image
imgExpand.ID = "imgExpand" &
Category.ProblemTypeId.ToString()
imgExpand.ImageUrl = "~/images/icons/118.png"
imgExpand.ToolTip = "View Details"
Dim imgCollapse As New WebControls.Image
imgCollapse.ID = "imgCollapse" &
Category.ProblemTypeId.ToString()
imgCollapse.ImageUrl = "~/images/icons/116.png"
imgCollapse.ToolTip = "Hide Details"
imgCollapse.Attributes.Add("style", "display:none")

cellImage.Controls.Add(imgExpand)
cellImage.Controls.Add(imgCollapse)

row.Controls.Add(cellLabel)
row.Controls.Add(cellDDL)
row.Controls.Add(cellImage)
table.Rows.Add(row)

pnlHeader.BackColor = Drawing.Color.FromArgb(255, 206,
204, 204)
End Sub

Protected Sub ddlAll_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub
The control renders fine. The problem I am having is that the
dynamically created dropdownlist (ddlAll) does not fire the
SelectedIndexChanged event. What am I missing?

Thanks,
Jeremy
Mar 17 '08 #2
The controls are added to a panel that is displayed after a button is
clicked on page. I set properties on the control and then call
Setup_Control creates all of the child controls on the button click.

On Mar 17, 10:45 am, bruce barker
<brucebar...@discussions.microsoft.comwrote:
when do you call Setup_Control() (and why do you have it?). it must be called
in oninit of the page, or better yet, change it to CreateChildControls.

-- bruce (sqlwork.com)

"jbec...@gmail.com" wrote:
Hi,
I am trying to create a custom server control that contains several
dropdownlists. The control looks like this:
Dim pnlHeader As New Panel
Protected Overrides Sub RenderContents(ByVal writer as HtmlTextWriter)
pnlHeader.RenderControl(writer)
End Sub
Public Sub Setup_Control()
Dim table As New HtmlControls.HtmlTable
table.Attributes.Add("style", "width:100%")
pnlHeader.Controls.Add(table)
Dim row As New HtmlControls.HtmlTableRow
Dim cellLabel As New HtmlControls.HtmlTableCell
cellLabel.Width = "60%"
Dim lblProblems As New Label
lblProblems.ID = "lbl" & Category.ProblemTypeId
lblProblems.Text = "Choose Vendor for All " &
Category.ProblemType & " Problems."
cellLabel.Controls.Add(lblProblems)
Dim cellDDL As New HtmlControls.HtmlTableCell
cellDDL.Width = "30%"
Dim ddlAll As New DropDownList
ddlAll.ID = "ddlVendorForAll" &
Category.ProblemTypeId.ToString()
ddlAll.AutoPostBack = True
Common.FillList(ddlAll, HeatMapData.GetVendors(PropertyId,
"[Choose a Vendor]"))
cellDDL.Controls.Add(ddlAll)
listDDL.Add(ddlAll)
AddHandler ddlAll.SelectedIndexChanged, AddressOf
ddlAll_SelectedIndexChanged
Dim cellImage As New HtmlControls.HtmlTableCell
cellImage.Width = "9%"
Dim imgExpand As New WebControls.Image
imgExpand.ID = "imgExpand" &
Category.ProblemTypeId.ToString()
imgExpand.ImageUrl = "~/images/icons/118.png"
imgExpand.ToolTip = "View Details"
Dim imgCollapse As New WebControls.Image
imgCollapse.ID = "imgCollapse" &
Category.ProblemTypeId.ToString()
imgCollapse.ImageUrl = "~/images/icons/116.png"
imgCollapse.ToolTip = "Hide Details"
imgCollapse.Attributes.Add("style", "display:none")
cellImage.Controls.Add(imgExpand)
cellImage.Controls.Add(imgCollapse)
row.Controls.Add(cellLabel)
row.Controls.Add(cellDDL)
row.Controls.Add(cellImage)
table.Rows.Add(row)
pnlHeader.BackColor = Drawing.Color.FromArgb(255, 206,
204, 204)
End Sub
Protected Sub ddlAll_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub
The control renders fine. The problem I am having is that the
dynamically created dropdownlist (ddlAll) does not fire the
SelectedIndexChanged event. What am I missing?
Thanks,
Jeremy
Mar 17 '08 #3
but then on postback you need to recreate the control (and its children) in
the oninit event so it can receive the postback data and fire the onchange
event. you can store in viewstate a flag to determine if this must be done.

-- bruce (sqlwork.com)
"jb*****@gmail.com" wrote:
The controls are added to a panel that is displayed after a button is
clicked on page. I set properties on the control and then call
Setup_Control creates all of the child controls on the button click.

On Mar 17, 10:45 am, bruce barker
<brucebar...@discussions.microsoft.comwrote:
when do you call Setup_Control() (and why do you have it?). it must be called
in oninit of the page, or better yet, change it to CreateChildControls.

-- bruce (sqlwork.com)

"jbec...@gmail.com" wrote:
Hi,
I am trying to create a custom server control that contains several
dropdownlists. The control looks like this:
Dim pnlHeader As New Panel
Protected Overrides Sub RenderContents(ByVal writer as HtmlTextWriter)
pnlHeader.RenderControl(writer)
End Sub
Public Sub Setup_Control()
Dim table As New HtmlControls.HtmlTable
table.Attributes.Add("style", "width:100%")
pnlHeader.Controls.Add(table)
Dim row As New HtmlControls.HtmlTableRow
Dim cellLabel As New HtmlControls.HtmlTableCell
cellLabel.Width = "60%"
Dim lblProblems As New Label
lblProblems.ID = "lbl" & Category.ProblemTypeId
lblProblems.Text = "Choose Vendor for All " &
Category.ProblemType & " Problems."
cellLabel.Controls.Add(lblProblems)
Dim cellDDL As New HtmlControls.HtmlTableCell
cellDDL.Width = "30%"
Dim ddlAll As New DropDownList
ddlAll.ID = "ddlVendorForAll" &
Category.ProblemTypeId.ToString()
ddlAll.AutoPostBack = True
Common.FillList(ddlAll, HeatMapData.GetVendors(PropertyId,
"[Choose a Vendor]"))
cellDDL.Controls.Add(ddlAll)
listDDL.Add(ddlAll)
AddHandler ddlAll.SelectedIndexChanged, AddressOf
ddlAll_SelectedIndexChanged
Dim cellImage As New HtmlControls.HtmlTableCell
cellImage.Width = "9%"
Dim imgExpand As New WebControls.Image
imgExpand.ID = "imgExpand" &
Category.ProblemTypeId.ToString()
imgExpand.ImageUrl = "~/images/icons/118.png"
imgExpand.ToolTip = "View Details"
Dim imgCollapse As New WebControls.Image
imgCollapse.ID = "imgCollapse" &
Category.ProblemTypeId.ToString()
imgCollapse.ImageUrl = "~/images/icons/116.png"
imgCollapse.ToolTip = "Hide Details"
imgCollapse.Attributes.Add("style", "display:none")
cellImage.Controls.Add(imgExpand)
cellImage.Controls.Add(imgCollapse)
row.Controls.Add(cellLabel)
row.Controls.Add(cellDDL)
row.Controls.Add(cellImage)
table.Rows.Add(row)
pnlHeader.BackColor = Drawing.Color.FromArgb(255, 206,
204, 204)
End Sub
Protected Sub ddlAll_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub
The control renders fine. The problem I am having is that the
dynamically created dropdownlist (ddlAll) does not fire the
SelectedIndexChanged event. What am I missing?
Thanks,
Jeremy

Mar 17 '08 #4
Do I need to rebind the dropdownlist?

On Mar 17, 11:56 am, bruce barker
<brucebar...@discussions.microsoft.comwrote:
but then on postback you need to recreate the control (and its children) in
the oninit event so it can receive the postback data and fire the onchange
event. you can store in viewstate a flag to determine if this must be done.

-- bruce (sqlwork.com)

"jbec...@gmail.com" wrote:
The controls are added to a panel that is displayed after a button is
clicked on page. I set properties on the control and then call
Setup_Control creates all of the child controls on the button click.
On Mar 17, 10:45 am, bruce barker
<brucebar...@discussions.microsoft.comwrote:
when do you call Setup_Control() (and why do you have it?). it must be called
in oninit of the page, or better yet, change it to CreateChildControls.
-- bruce (sqlwork.com)
"jbec...@gmail.com" wrote:
Hi,
I am trying to create a custom server control that contains several
dropdownlists. The control looks like this:
Dim pnlHeader As New Panel
Protected Overrides Sub RenderContents(ByVal writer as HtmlTextWriter)
pnlHeader.RenderControl(writer)
End Sub
Public Sub Setup_Control()
Dim table As New HtmlControls.HtmlTable
table.Attributes.Add("style", "width:100%")
pnlHeader.Controls.Add(table)
Dim row As New HtmlControls.HtmlTableRow
Dim cellLabel As New HtmlControls.HtmlTableCell
cellLabel.Width = "60%"
Dim lblProblems As New Label
lblProblems.ID = "lbl" & Category.ProblemTypeId
lblProblems.Text = "Choose Vendor for All " &
Category.ProblemType & " Problems."
cellLabel.Controls.Add(lblProblems)
Dim cellDDL As New HtmlControls.HtmlTableCell
cellDDL.Width = "30%"
Dim ddlAll As New DropDownList
ddlAll.ID = "ddlVendorForAll" &
Category.ProblemTypeId.ToString()
ddlAll.AutoPostBack = True
Common.FillList(ddlAll, HeatMapData.GetVendors(PropertyId,
"[Choose a Vendor]"))
cellDDL.Controls.Add(ddlAll)
listDDL.Add(ddlAll)
AddHandler ddlAll.SelectedIndexChanged, AddressOf
ddlAll_SelectedIndexChanged
Dim cellImage As New HtmlControls.HtmlTableCell
cellImage.Width = "9%"
Dim imgExpand As New WebControls.Image
imgExpand.ID = "imgExpand" &
Category.ProblemTypeId.ToString()
imgExpand.ImageUrl = "~/images/icons/118.png"
imgExpand.ToolTip = "View Details"
Dim imgCollapse As New WebControls.Image
imgCollapse.ID = "imgCollapse" &
Category.ProblemTypeId.ToString()
imgCollapse.ImageUrl = "~/images/icons/116.png"
imgCollapse.ToolTip = "Hide Details"
imgCollapse.Attributes.Add("style", "display:none")
cellImage.Controls.Add(imgExpand)
cellImage.Controls.Add(imgCollapse)
row.Controls.Add(cellLabel)
row.Controls.Add(cellDDL)
row.Controls.Add(cellImage)
table.Rows.Add(row)
pnlHeader.BackColor = Drawing.Color.FromArgb(255, 206,
204, 204)
End Sub
Protected Sub ddlAll_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub
The control renders fine. The problem I am having is that the
dynamically created dropdownlist (ddlAll) does not fire the
SelectedIndexChanged event. What am I missing?
Thanks,
Jeremy
Mar 17 '08 #5
Nevermind, I worked around it. I'm just inspecting the internal
controls through a method call and just worked around the event
problem.

On Mar 17, 12:01 pm, "jbec...@gmail.com" <jbec...@gmail.comwrote:
Do I need to rebind the dropdownlist?

On Mar 17, 11:56 am, bruce barker

<brucebar...@discussions.microsoft.comwrote:
but then on postback you need to recreate the control (and its children) in
the oninit event so it can receive the postback data and fire the onchange
event. you can store in viewstate a flag to determine if this must be done.
-- bruce (sqlwork.com)
"jbec...@gmail.com" wrote:
The controls are added to a panel that is displayed after a button is
clicked on page. I set properties on the control and then call
Setup_Control creates all of the child controls on the button click.
On Mar 17, 10:45 am, bruce barker
<brucebar...@discussions.microsoft.comwrote:
when do you call Setup_Control() (and why do you have it?). it must be called
in oninit of the page, or better yet, change it to CreateChildControls.
-- bruce (sqlwork.com)
"jbec...@gmail.com" wrote:
Hi,
I am trying to create a custom server control that contains several
dropdownlists. The control looks like this:
Dim pnlHeader As New Panel
Protected Overrides Sub RenderContents(ByVal writer as HtmlTextWriter)
pnlHeader.RenderControl(writer)
End Sub
Public Sub Setup_Control()
Dim table As New HtmlControls.HtmlTable
table.Attributes.Add("style", "width:100%")
pnlHeader.Controls.Add(table)
Dim row As New HtmlControls.HtmlTableRow
Dim cellLabel As New HtmlControls.HtmlTableCell
cellLabel.Width = "60%"
Dim lblProblems As New Label
lblProblems.ID = "lbl" & Category.ProblemTypeId
lblProblems.Text = "Choose Vendor for All " &
Category.ProblemType & " Problems."
cellLabel.Controls.Add(lblProblems)
Dim cellDDL As New HtmlControls.HtmlTableCell
cellDDL.Width = "30%"
Dim ddlAll As New DropDownList
ddlAll.ID = "ddlVendorForAll" &
Category.ProblemTypeId.ToString()
ddlAll.AutoPostBack = True
Common.FillList(ddlAll, HeatMapData.GetVendors(PropertyId,
"[Choose a Vendor]"))
cellDDL.Controls.Add(ddlAll)
listDDL.Add(ddlAll)
AddHandler ddlAll.SelectedIndexChanged, AddressOf
ddlAll_SelectedIndexChanged
Dim cellImage As New HtmlControls.HtmlTableCell
cellImage.Width = "9%"
Dim imgExpand As New WebControls.Image
imgExpand.ID = "imgExpand" &
Category.ProblemTypeId.ToString()
imgExpand.ImageUrl = "~/images/icons/118.png"
imgExpand.ToolTip = "View Details"
Dim imgCollapse As New WebControls.Image
imgCollapse.ID = "imgCollapse" &
Category.ProblemTypeId.ToString()
imgCollapse.ImageUrl = "~/images/icons/116.png"
imgCollapse.ToolTip = "Hide Details"
imgCollapse.Attributes.Add("style", "display:none")
cellImage.Controls.Add(imgExpand)
cellImage.Controls.Add(imgCollapse)
row.Controls.Add(cellLabel)
row.Controls.Add(cellDDL)
row.Controls.Add(cellImage)
table.Rows.Add(row)
pnlHeader.BackColor = Drawing.Color.FromArgb(255, 206,
204, 204)
End Sub
Protected Sub ddlAll_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
....
End Sub
The control renders fine. The problem I am having is that the
dynamically created dropdownlist (ddlAll) does not fire the
SelectedIndexChanged event. What am I missing?
Thanks,
Jeremy
Mar 17 '08 #6

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

Similar topics

3
by: Christoph Schittko [MVP] | last post by:
All, I am trying to display a winforms user control inside an HTML page through an <object> tag. Everything works fine and dandy until I sign the assembly that contains the control. Once I start...
9
by: wASP | last post by:
Hello again to all of you geniuses, I'm having a problem trying to load dynamic controls at the initialization phase. I've read the docs, and I thought I had it figured out:...
0
by: Earl Teigrob | last post by:
I am building a custom control that I want to server as a container for child controls that can be dynamically added to this control. I can persist the child controls that are added to my custom...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
11
by: Nick Gilbert | last post by:
Hi, How can I create a custom control which will wrap its content in a header and footer? eg: Is it possible to create a .NET user control which can surround other controls? eg:...
4
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
4
by: Peted | last post by:
Hi, this prob isnt the right forum but i got no response from the other forums so i hope someone can point me in the right direction. I know you can write a custom control in C# and host...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.