Hosting controls in a custom server control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jbeckh2@gmail.com

    #1

    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.Rende rControl(writer )
    End Sub

    Public Sub Setup_Control()
    Dim table As New HtmlControls.Ht mlTable
    table.Attribute s.Add("style", "width:100% ")
    pnlHeader.Contr ols.Add(table)

    Dim row As New HtmlControls.Ht mlTableRow

    Dim cellLabel As New HtmlControls.Ht mlTableCell
    cellLabel.Width = "60%"
    Dim lblProblems As New Label
    lblProblems.ID = "lbl" & Category.Proble mTypeId
    lblProblems.Tex t = "Choose Vendor for All " &
    Category.Proble mType & " Problems."
    cellLabel.Contr ols.Add(lblProb lems)

    Dim cellDDL As New HtmlControls.Ht mlTableCell
    cellDDL.Width = "30%"
    Dim ddlAll As New DropDownList
    ddlAll.ID = "ddlVendorForAl l" &
    Category.Proble mTypeId.ToStrin g()
    ddlAll.AutoPost Back = True
    Common.FillList (ddlAll, HeatMapData.Get Vendors(Propert yId,
    "[Choose a Vendor]"))
    cellDDL.Control s.Add(ddlAll)
    listDDL.Add(ddl All)
    AddHandler ddlAll.Selected IndexChanged, AddressOf
    ddlAll_Selected IndexChanged

    Dim cellImage As New HtmlControls.Ht mlTableCell
    cellImage.Width = "9%"
    Dim imgExpand As New WebControls.Ima ge
    imgExpand.ID = "imgExpand" &
    Category.Proble mTypeId.ToStrin g()
    imgExpand.Image Url = "~/images/icons/118.png"
    imgExpand.ToolT ip = "View Details"


    Dim imgCollapse As New WebControls.Ima ge
    imgCollapse.ID = "imgCollaps e" &
    Category.Proble mTypeId.ToStrin g()
    imgCollapse.Ima geUrl = "~/images/icons/116.png"
    imgCollapse.Too lTip = "Hide Details"
    imgCollapse.Att ributes.Add("st yle", "display:no ne")

    cellImage.Contr ols.Add(imgExpa nd)
    cellImage.Contr ols.Add(imgColl apse)

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

    pnlHeader.BackC olor = Drawing.Color.F romArgb(255, 206,
    204, 204)
    End Sub

    Protected Sub ddlAll_Selected IndexChanged(By Val sender As Object,
    ByVal e As System.EventArg s)
    ....
    End Sub


    The control renders fine. The problem I am having is that the
    dynamically created dropdownlist (ddlAll) does not fire the
    SelectedIndexCh anged event. What am I missing?

    Thanks,
    Jeremy
  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: Hosting controls in a custom server control

    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 CreateChildCont rols.


    -- bruce (sqlwork.com)


    "jbeckh2@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.Rende rControl(writer )
    End Sub
    >
    Public Sub Setup_Control()
    Dim table As New HtmlControls.Ht mlTable
    table.Attribute s.Add("style", "width:100% ")
    pnlHeader.Contr ols.Add(table)
    >
    Dim row As New HtmlControls.Ht mlTableRow
    >
    Dim cellLabel As New HtmlControls.Ht mlTableCell
    cellLabel.Width = "60%"
    Dim lblProblems As New Label
    lblProblems.ID = "lbl" & Category.Proble mTypeId
    lblProblems.Tex t = "Choose Vendor for All " &
    Category.Proble mType & " Problems."
    cellLabel.Contr ols.Add(lblProb lems)
    >
    Dim cellDDL As New HtmlControls.Ht mlTableCell
    cellDDL.Width = "30%"
    Dim ddlAll As New DropDownList
    ddlAll.ID = "ddlVendorForAl l" &
    Category.Proble mTypeId.ToStrin g()
    ddlAll.AutoPost Back = True
    Common.FillList (ddlAll, HeatMapData.Get Vendors(Propert yId,
    "[Choose a Vendor]"))
    cellDDL.Control s.Add(ddlAll)
    listDDL.Add(ddl All)
    AddHandler ddlAll.Selected IndexChanged, AddressOf
    ddlAll_Selected IndexChanged
    >
    Dim cellImage As New HtmlControls.Ht mlTableCell
    cellImage.Width = "9%"
    Dim imgExpand As New WebControls.Ima ge
    imgExpand.ID = "imgExpand" &
    Category.Proble mTypeId.ToStrin g()
    imgExpand.Image Url = "~/images/icons/118.png"
    imgExpand.ToolT ip = "View Details"
    >
    >
    Dim imgCollapse As New WebControls.Ima ge
    imgCollapse.ID = "imgCollaps e" &
    Category.Proble mTypeId.ToStrin g()
    imgCollapse.Ima geUrl = "~/images/icons/116.png"
    imgCollapse.Too lTip = "Hide Details"
    imgCollapse.Att ributes.Add("st yle", "display:no ne")
    >
    cellImage.Contr ols.Add(imgExpa nd)
    cellImage.Contr ols.Add(imgColl apse)
    >
    row.Controls.Ad d(cellLabel)
    row.Controls.Ad d(cellDDL)
    row.Controls.Ad d(cellImage)
    table.Rows.Add( row)
    >
    pnlHeader.BackC olor = Drawing.Color.F romArgb(255, 206,
    204, 204)
    End Sub
    >
    Protected Sub ddlAll_Selected IndexChanged(By Val sender As Object,
    ByVal e As System.EventArg s)
    ....
    End Sub
    >
    >
    The control renders fine. The problem I am having is that the
    dynamically created dropdownlist (ddlAll) does not fire the
    SelectedIndexCh anged event. What am I missing?
    >
    Thanks,
    Jeremy
    >

    Comment

    • jbeckh2@gmail.com

      #3
      Re: Hosting controls in a custom server control

      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...@di scussions.micro soft.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 CreateChildCont rols.
      >
      -- 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.Rende rControl(writer )
      End Sub
      >
      Public Sub Setup_Control()
      Dim table As New HtmlControls.Ht mlTable
      table.Attribute s.Add("style", "width:100% ")
      pnlHeader.Contr ols.Add(table)
      >
      Dim row As New HtmlControls.Ht mlTableRow
      >
      Dim cellLabel As New HtmlControls.Ht mlTableCell
      cellLabel.Width = "60%"
      Dim lblProblems As New Label
      lblProblems.ID = "lbl" & Category.Proble mTypeId
      lblProblems.Tex t = "Choose Vendor for All " &
      Category.Proble mType & " Problems."
      cellLabel.Contr ols.Add(lblProb lems)
      >
      Dim cellDDL As New HtmlControls.Ht mlTableCell
      cellDDL.Width = "30%"
      Dim ddlAll As New DropDownList
      ddlAll.ID = "ddlVendorForAl l" &
      Category.Proble mTypeId.ToStrin g()
      ddlAll.AutoPost Back = True
      Common.FillList (ddlAll, HeatMapData.Get Vendors(Propert yId,
      "[Choose a Vendor]"))
      cellDDL.Control s.Add(ddlAll)
      listDDL.Add(ddl All)
      AddHandler ddlAll.Selected IndexChanged, AddressOf
      ddlAll_Selected IndexChanged
      >
      Dim cellImage As New HtmlControls.Ht mlTableCell
      cellImage.Width = "9%"
      Dim imgExpand As New WebControls.Ima ge
      imgExpand.ID = "imgExpand" &
      Category.Proble mTypeId.ToStrin g()
      imgExpand.Image Url = "~/images/icons/118.png"
      imgExpand.ToolT ip = "View Details"
      >
      Dim imgCollapse As New WebControls.Ima ge
      imgCollapse.ID = "imgCollaps e" &
      Category.Proble mTypeId.ToStrin g()
      imgCollapse.Ima geUrl = "~/images/icons/116.png"
      imgCollapse.Too lTip = "Hide Details"
      imgCollapse.Att ributes.Add("st yle", "display:no ne")
      >
      cellImage.Contr ols.Add(imgExpa nd)
      cellImage.Contr ols.Add(imgColl apse)
      >
      row.Controls.Ad d(cellLabel)
      row.Controls.Ad d(cellDDL)
      row.Controls.Ad d(cellImage)
      table.Rows.Add( row)
      >
      pnlHeader.BackC olor = Drawing.Color.F romArgb(255, 206,
      204, 204)
      End Sub
      >
      Protected Sub ddlAll_Selected IndexChanged(By Val sender As Object,
      ByVal e As System.EventArg s)
      ....
      End Sub
      >
      The control renders fine. The problem I am having is that the
      dynamically created dropdownlist (ddlAll) does not fire the
      SelectedIndexCh anged event. What am I missing?
      >
      Thanks,
      Jeremy

      Comment

      • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

        #4
        Re: Hosting controls in a custom server control

        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)


        "jbeckh2@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...@di scussions.micro soft.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 CreateChildCont rols.

        -- 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.Rende rControl(writer )
        End Sub
        Public Sub Setup_Control()
        Dim table As New HtmlControls.Ht mlTable
        table.Attribute s.Add("style", "width:100% ")
        pnlHeader.Contr ols.Add(table)
        Dim row As New HtmlControls.Ht mlTableRow
        Dim cellLabel As New HtmlControls.Ht mlTableCell
        cellLabel.Width = "60%"
        Dim lblProblems As New Label
        lblProblems.ID = "lbl" & Category.Proble mTypeId
        lblProblems.Tex t = "Choose Vendor for All " &
        Category.Proble mType & " Problems."
        cellLabel.Contr ols.Add(lblProb lems)
        Dim cellDDL As New HtmlControls.Ht mlTableCell
        cellDDL.Width = "30%"
        Dim ddlAll As New DropDownList
        ddlAll.ID = "ddlVendorForAl l" &
        Category.Proble mTypeId.ToStrin g()
        ddlAll.AutoPost Back = True
        Common.FillList (ddlAll, HeatMapData.Get Vendors(Propert yId,
        "[Choose a Vendor]"))
        cellDDL.Control s.Add(ddlAll)
        listDDL.Add(ddl All)
        AddHandler ddlAll.Selected IndexChanged, AddressOf
        ddlAll_Selected IndexChanged
        Dim cellImage As New HtmlControls.Ht mlTableCell
        cellImage.Width = "9%"
        Dim imgExpand As New WebControls.Ima ge
        imgExpand.ID = "imgExpand" &
        Category.Proble mTypeId.ToStrin g()
        imgExpand.Image Url = "~/images/icons/118.png"
        imgExpand.ToolT ip = "View Details"
        Dim imgCollapse As New WebControls.Ima ge
        imgCollapse.ID = "imgCollaps e" &
        Category.Proble mTypeId.ToStrin g()
        imgCollapse.Ima geUrl = "~/images/icons/116.png"
        imgCollapse.Too lTip = "Hide Details"
        imgCollapse.Att ributes.Add("st yle", "display:no ne")
        cellImage.Contr ols.Add(imgExpa nd)
        cellImage.Contr ols.Add(imgColl apse)
        row.Controls.Ad d(cellLabel)
        row.Controls.Ad d(cellDDL)
        row.Controls.Ad d(cellImage)
        table.Rows.Add( row)
        pnlHeader.BackC olor = Drawing.Color.F romArgb(255, 206,
        204, 204)
        End Sub
        Protected Sub ddlAll_Selected IndexChanged(By Val sender As Object,
        ByVal e As System.EventArg s)
        ....
        End Sub
        The control renders fine. The problem I am having is that the
        dynamically created dropdownlist (ddlAll) does not fire the
        SelectedIndexCh anged event. What am I missing?
        Thanks,
        Jeremy
        >
        >

        Comment

        • jbeckh2@gmail.com

          #5
          Re: Hosting controls in a custom server control

          Do I need to rebind the dropdownlist?

          On Mar 17, 11:56 am, bruce barker
          <brucebar...@di scussions.micro soft.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...@di scussions.micro soft.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 CreateChildCont rols.
          >
          -- 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.Rende rControl(writer )
          End Sub
          >
          Public Sub Setup_Control()
          Dim table As New HtmlControls.Ht mlTable
          table.Attribute s.Add("style", "width:100% ")
          pnlHeader.Contr ols.Add(table)
          >
          Dim row As New HtmlControls.Ht mlTableRow
          >
          Dim cellLabel As New HtmlControls.Ht mlTableCell
          cellLabel.Width = "60%"
          Dim lblProblems As New Label
          lblProblems.ID = "lbl" & Category.Proble mTypeId
          lblProblems.Tex t = "Choose Vendor for All " &
          Category.Proble mType & " Problems."
          cellLabel.Contr ols.Add(lblProb lems)
          >
          Dim cellDDL As New HtmlControls.Ht mlTableCell
          cellDDL.Width = "30%"
          Dim ddlAll As New DropDownList
          ddlAll.ID = "ddlVendorForAl l" &
          Category.Proble mTypeId.ToStrin g()
          ddlAll.AutoPost Back = True
          Common.FillList (ddlAll, HeatMapData.Get Vendors(Propert yId,
          "[Choose a Vendor]"))
          cellDDL.Control s.Add(ddlAll)
          listDDL.Add(ddl All)
          AddHandler ddlAll.Selected IndexChanged, AddressOf
          ddlAll_Selected IndexChanged
          >
          Dim cellImage As New HtmlControls.Ht mlTableCell
          cellImage.Width = "9%"
          Dim imgExpand As New WebControls.Ima ge
          imgExpand.ID = "imgExpand" &
          Category.Proble mTypeId.ToStrin g()
          imgExpand.Image Url = "~/images/icons/118.png"
          imgExpand.ToolT ip = "View Details"
          >
          Dim imgCollapse As New WebControls.Ima ge
          imgCollapse.ID = "imgCollaps e" &
          Category.Proble mTypeId.ToStrin g()
          imgCollapse.Ima geUrl = "~/images/icons/116.png"
          imgCollapse.Too lTip = "Hide Details"
          imgCollapse.Att ributes.Add("st yle", "display:no ne")
          >
          cellImage.Contr ols.Add(imgExpa nd)
          cellImage.Contr ols.Add(imgColl apse)
          >
          row.Controls.Ad d(cellLabel)
          row.Controls.Ad d(cellDDL)
          row.Controls.Ad d(cellImage)
          table.Rows.Add( row)
          >
          pnlHeader.BackC olor = Drawing.Color.F romArgb(255, 206,
          204, 204)
          End Sub
          >
          Protected Sub ddlAll_Selected IndexChanged(By Val sender As Object,
          ByVal e As System.EventArg s)
          ....
          End Sub
          >
          The control renders fine. The problem I am having is that the
          dynamically created dropdownlist (ddlAll) does not fire the
          SelectedIndexCh anged event. What am I missing?
          >
          Thanks,
          Jeremy

          Comment

          • jbeckh2@gmail.com

            #6
            Re: Hosting controls in a custom server control

            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...@di scussions.micro soft.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...@di scussions.micro soft.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 CreateChildCont rols.
            >
            -- 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.Rende rControl(writer )
            End Sub
            >
            Public Sub Setup_Control()
            Dim table As New HtmlControls.Ht mlTable
            table.Attribute s.Add("style", "width:100% ")
            pnlHeader.Contr ols.Add(table)
            >
            Dim row As New HtmlControls.Ht mlTableRow
            >
            Dim cellLabel As New HtmlControls.Ht mlTableCell
            cellLabel.Width = "60%"
            Dim lblProblems As New Label
            lblProblems.ID = "lbl" & Category.Proble mTypeId
            lblProblems.Tex t = "Choose Vendor for All " &
            Category.Proble mType & " Problems."
            cellLabel.Contr ols.Add(lblProb lems)
            >
            Dim cellDDL As New HtmlControls.Ht mlTableCell
            cellDDL.Width = "30%"
            Dim ddlAll As New DropDownList
            ddlAll.ID = "ddlVendorForAl l" &
            Category.Proble mTypeId.ToStrin g()
            ddlAll.AutoPost Back = True
            Common.FillList (ddlAll, HeatMapData.Get Vendors(Propert yId,
            "[Choose a Vendor]"))
            cellDDL.Control s.Add(ddlAll)
            listDDL.Add(ddl All)
            AddHandler ddlAll.Selected IndexChanged, AddressOf
            ddlAll_Selected IndexChanged
            >
            Dim cellImage As New HtmlControls.Ht mlTableCell
            cellImage.Width = "9%"
            Dim imgExpand As New WebControls.Ima ge
            imgExpand.ID = "imgExpand" &
            Category.Proble mTypeId.ToStrin g()
            imgExpand.Image Url = "~/images/icons/118.png"
            imgExpand.ToolT ip = "View Details"
            >
            Dim imgCollapse As New WebControls.Ima ge
            imgCollapse.ID = "imgCollaps e" &
            Category.Proble mTypeId.ToStrin g()
            imgCollapse.Ima geUrl = "~/images/icons/116.png"
            imgCollapse.Too lTip = "Hide Details"
            imgCollapse.Att ributes.Add("st yle", "display:no ne")
            >
            cellImage.Contr ols.Add(imgExpa nd)
            cellImage.Contr ols.Add(imgColl apse)
            >
            row.Controls.Ad d(cellLabel)
            row.Controls.Ad d(cellDDL)
            row.Controls.Ad d(cellImage)
            table.Rows.Add( row)
            >
            pnlHeader.BackC olor = Drawing.Color.F romArgb(255, 206,
            204, 204)
            End Sub
            >
            Protected Sub ddlAll_Selected IndexChanged(By Val sender As Object,
            ByVal e As System.EventArg s)
            ....
            End Sub
            >
            The control renders fine. The problem I am having is that the
            dynamically created dropdownlist (ddlAll) does not fire the
            SelectedIndexCh anged event. What am I missing?
            >
            Thanks,
            Jeremy

            Comment

            Working...