事件触发错误 [英] Error in event firing

查看:109
本文介绍了事件触发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..



我有一个文本框,我试图在其OnBlur事件上调用一个函数。

该函数在aspx.cs页面中定义。

当我尝试调试时出现问题,它表示函数 Text_Blur 未定义。

下面是代码:

前端:



Hello folks..

I have a text box in which I m trying to call a function on its OnBlur event.
The function is defined in the aspx.cs page.
Problem arises when I try to debug, it says the function Text_Blur is not defined.
Below is the code:
Front end:

<asp:TextBox ID="txtAutoComplete" runat="server" OnBlur="Text_Blur"  CssClass="TextStyleFilter"></asp:TextBox>





Code Behind,aspx.cs:



Code Behind, aspx.cs:

public event EventHandler OnChange;

 protected void Text_Blur(object sender, EventArgs e)
        {

            if (OnChange != null)
                OnChange(this, EventArgs.Empty);
        }





事件处理程序OnChange用于调用另一个用户控件中的事件。

我哪里错了?任何建议都将受到高度赞赏。



-Anurag



The event handler OnChange is to invoke an event in another user control.
Where am I going wrong?Any suggestions will be highly appreciated.

-Anurag

推荐答案





OnBlur是asp:Textbox的javascript函数。你应该用javascript编写函数,而不是用C#代码编写。



示例:

http://forums.asp.net/t/992496.aspx/1 [ ^ ]



谢谢,

Vamsi
Hi,

OnBlur is a javascript function for asp:Textbox. You should be writing the function in javascript instead of writing it in C# code.

Example:
http://forums.asp.net/t/992496.aspx/1[^]

Thank you,
Vamsi


如果你真的需要在服务器端处理事件,有一个用于模糊的javascript处理程序,然后在该处理程序中单击一个asp:Button,你就可以了然后在你的代码中处理该方法。但像以前的解决方案完全在javascript中处理可能是最好的用户体验。也许使用ajax将您拥有的任何信息发送到Web服务。
Uou could if you really need to handler the event on server side, have a javascript handler for blur and then click an asp:Button in that handler that will then handler the method in your code behind. But like the previous solution handling fully in javascript might be best for user experience. Maybe send whatever info you have to a web service using ajax.


这篇关于事件触发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆