Asp.net RenderControl方法不渲染下拉列表的自动回发
我有点困惑为什么在使用 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生成的。
有解决办法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是猜测,但这可能是因为它不在
form
元素内。你为什么要这么做?Just a guess, but it might be because it's not inside a
form
element. Why would you want to do this anyway?