0

我有点困惑,为什么在使用 RenderControl 方法时,asp.net 不呈现 autopostback 属性设置为 true 的下拉列表。

例如

 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)

我的输出呈现的下拉列表没有 onchange="javascript:setTimeout('__doPostBack(\ddl1\',\'\')', 0)" 正常使用下拉列表时由 asp.net 生成的。

有解决办法吗?

4

1 回答 1

0

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

于 2010-03-12T10:49:52.603 回答