Fire ontextchanged()事件的一个asp:TextBox通过javascript
我有一个 asp:TextBox
,看起来像以下
I have an asp:TextBox
that looks like the following
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" ontextchanged="txtG1_TextChanged" onmouseout="javascript:RefreshIt(this)"/>
和一个javascript函数 RefreshIt()
正确地在文本框的 mouseout 之间触发。
and a javascript function RefreshIt()
that correctly fires each time I mouseout of the textbox.
我试图让mouseout事件触发 asp的
。 ontextchanged
事件:文本框
I'm trying to have the mouseout event trigger the ontextchanged
event of the asp:TextBox
.
各种SO帖子已经推荐了以下技术,似乎不起作用。
Various SO posts have recommended the following techniques, which do not seem to work.
function RefreshIt(selectObj){
selectObj.ontextchanged();
}
function RefreshIt(selectObj){
selectObj.fireEvent('ontextchanged');
}
任何帮助将不胜感激。
请参阅: https://*.com/a/3777/892536
使用此链接,我能够提出产生与您正在寻找的相同结果的内容。不知道这是否适用于您的应用程序,但它可以正常工作:
Using this link, I was able to come up with something that produced the same results you are looking for. Not sure if this is okay for your application or not, but it works:
RefreshIt函数用参数进行回发:
Changed the RefreshIt function to do a postback with an argument:
<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'函数:
Code Behind:
Added 'IPostBackEventHandler' to the page and handled the 'RaisePostBackEvent' function:
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();
}
}