Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Hosting controls in a custom server control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jbeckh2@gmail.com - 17 Mar 2008 16:24 GMT
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
bruce barker - 17 Mar 2008 16:45 GMT
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)

> Hi,
>
[quoted text clipped - 73 lines]
> Thanks,
> Jeremy
jbeckh2@gmail.com - 17 Mar 2008 17:01 GMT
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.com> wrote:
> 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.
[quoted text clipped - 79 lines]
> > Thanks,
> > Jeremy
bruce barker - 17 Mar 2008 17:56 GMT
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)

> 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
[quoted text clipped - 85 lines]
> > > Thanks,
> > > Jeremy
jbeckh2@gmail.com - 17 Mar 2008 18:01 GMT
Do I need to rebind the dropdownlist?

On Mar 17, 11:56 am, bruce barker
<brucebar...@discussions.microsoft.com> wrote:
> 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
[quoted text clipped - 92 lines]
> > > > Thanks,
> > > > Jeremy
jbeckh2@gmail.com - 17 Mar 2008 20:49 GMT
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.com> wrote:
> Do I need to rebind the dropdownlist?
>
[quoted text clipped - 97 lines]
> > > > > Thanks,
> > > > > Jeremy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.