当我查看源代码时,我有一个看起来像这样的ASP.NET DDL:
<select name="testControl" onchange="DoCustomStuff();setTimeout('__doPostBack(\'testControl\',\'\')', 0)" id="testControl">
在.cs页面上看起来像这样:
<asp:DropDownList ID="testControl" runat="server" onchange="DoCustomStuff()" OnSelectedIndexChanged="testControl_Changed" AutoPostBack="true" />
任何人都可以在这样的DDL上看到使用onchange和AutoPostBack =“true”的问题吗?我问,因为我们有一些用户似乎没有正确调用DoCustomStuff(),我想知道在DoCustomStuff()完成其工作之前是否可以执行__doPostBack()。
答案 0 :(得分:0)
尝试手动附加回发引用:
Page.ClientScript.RegisterClientScriptBlock(
typeof(_Default),
"PageScripts",
string.Format("function DoCustomStuff() { /* Your Code Here */ {0} }", Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))
);
testControl.Attributes["onchange"] = "DoCustomStuff();";
这为您提供了回发客户端参考:
Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))