使用模型poppup时如何触发文本更改事件...... [英] how to fire the text changed event when using model poppup ......

查看:89
本文介绍了使用模型poppup时如何触发文本更改事件......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我用过模型弹出扩展器...
我用的是窗板.
现在我需要在隐藏弹出窗口时触发文本更改事件.
但是当我使用此代码时onclick事件正在工作....


document.forms ["aspnetForm"].elements ["ctl00_ContentPlaceHolder1_btnClick"].click()


我需要文本更改事件....


i have used model popup extender ...
and i used panel for window.
now i need to fire the text changed event when i hide the popup window.
but onclick event is working when i use this code ....


document.forms["aspnetForm"].elements["ctl00_ContentPlaceHolder1_btnClick"].click()


i need text changed event....

推荐答案

以下是带有适当注释的示例代码:

Here is the sample code with proper comments:

// to register the ASP.NET server control
Page.GetPostBackEventReference(txtBox1);

//event to fire the TextChanged event of txtBox1
__doPostBack("txtBox1", "TextChanged");

// JavaScript function to handle the situation when the user just wanted to type
function DoPostBack()
{
   __doPostBack("txtBox1", "TextChanged");
}

//function on the OnChange event
if(!IsPostback)
{
    /...Implementation.../ 
    txtBox1.Attributes.Add("OnChange", "javascript:return DoPostBack()")
}


问题还不是100%清楚,所以我想给您一个一般的想法,您可以从他们开始.

您不能从声明了事件的类外部触发任何事件.换句话说,如果您没有在类中声明某些事件对象,则无法直接触发它.即使在派生类中也无法做到这一点.它与对类型及其成员,访问修饰符或任何其他内容的访问无关.这是完全不可能的.这样做是有目的的.与常规"委托实例相比,事件的重要限制之一是防呆功能.

就是说,您永远不需要它.您只能间接触发事件.例如,如果您的事件是TextChanged,则只能通过实际更改文本来间接触发此事件.

那么,您该怎么办?首先,您应该了解触发特定事件永远不是您的最终目标.您只需要在其他事件上调用相同的方法即可.没有什么可以阻止您这样做的.换句话说,不要在事件本身的处理程序主体中编写处理程序的某些代码.实际上,从不做.写一些可以从一个以上的地方调用的方法.事件TextChanged的处理程序在其主体中应该只调用此方法.并从您需要的任何其他位置调用相同的方法.很简单,不是吗?

—SA
The question is not 100% clear, so I want to give you one general idea, and you can start from their.

You cannot fire any event from outside the class where event is declared. In other words, if you did not declare some event object in your class, you have no way to fire it directly. You cannot do it even in a derived class. It has nothing to do with access to the types and their members, access modifiers or anything at all; this is totally impossible. This is done for a purpose; one of the important limitations of the events compared to "regular" delegate instances, a fool-proof feature.

That said, you never really need it. You can only fire event indirectly. For example, if your event is TextChanged, you only can fire this event indirectly, by actually changing the text.

So, what to do in your case? First of all, you should understand that firing certain event is never your ultimate goal. You just need to call the same method on some other event. Nothing prevent you from doing that. In other words, don''t write some code of the handler in the body of the handler of the event itself. Actually, never do. Write some single method which you can call from more then one place. Your handler of the event TextChanged should have only one call of this method in its body. And call the same method from any other place you need. Simple, isn''t it?

—SA


这篇关于使用模型poppup时如何触发文本更改事件......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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