当我查看源代码时,我有一个看起来像这样的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" />

任何人都可以看到使用onchange和AutoPostBack = <!>的问题吗?true <!> quot;在像这样的DDL?我问,因为我们有一些用户似乎没有正确调用DoCustomStuff(),我想知道在DoCustomStuff()完成其工作之前是否可以执行__doPostBack()。

有帮助吗?

解决方案

尝试手动附加回发引用:

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))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top