请参阅:https ://stackoverflow.com/a/3777/892536
使用此链接,我能够想出与您正在寻找的结果相同的东西。不确定这是否适合您的应用程序,但它有效:
ASP:
将 RefreshIt 函数更改为使用参数进行回发:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
代码背后:
在页面中添加了“IPostBackEventHandler”并处理了“RaisePostBackEvent”函数:
public partial class _Default : System.Web.UI.Page, IPostBackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void RaisePostBackEvent(string Arg)
{
if (txtG1.ID == Arg)
txtG1_TextChanged(txtG1, null);
}
protected void txtG1_TextChanged(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
}
}