Asp.net RenderControl method not rendering autopostback for dropdownlist

Posted by Tanya on Stack Overflow See other posts from Stack Overflow or by Tanya
Published on 2010-03-12T10:43:29Z Indexed on 2010/03/12 10:47 UTC
Read the original article Hit count: 529

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?

© Stack Overflow or respective owner

Related posts about dropdownlist

Related posts about rendercontrol