views:

238

answers:

1

Hi all, i am bit confused as to why asp.net does not render a dropdownlist with the autopostback property set to true when using the RenderControl method.

eg

 Dim sw As New IO.StringWriter
    Dim tw As New HtmlTextWriter(sw)

    Dim table As New Table

    table.Rows.Add(New TableRow)
    Dim tr As TableRow = table.Rows(0)

    tr.Cells.Add(New TableCell)
    Dim tc As TableCell = tr.Cells(0)

    Dim ddlMyValues As New DropDownList
    ddlMyValues.ID = "ddl1"

    ddlMyValues.Items.Add("Test1")
    ddlMyValues.Items.Add("Test2")
    ddlMyValues.Items.Add("Test3")
    ddlMyValues.AutoPostBack = True

    tc.Controls.Add(ddlMyValues)
    table.RenderControl(tw)

    Debug.WriteLine(sw.ToString)

my output renders the dropdown list without the onchange="javascript:setTimeout('__doPostBack(\ddl1\',\'\')', 0)" that is generated by asp.net when using the dropdownlist normally.

Is there a work around to this?

A: 

Just a guess, but it might be because it's not inside a form element. Why would you want to do this anyway?

Dead account
Hi Ian, i am working with a control that another developer created, and he goes through this routine to create a row of controls. I am extend his control by adding a validation to drop downs which i cannot achieve!
Tanya
Sounds like an awful mess. If you don't need to dynamically create HTML output why not just put the controls in a usercontrol rather than using the HTMLWriter?
Dead account