如何在用户定义方法中调用从用户控件下拉选定的事件到aspx.cs。 [英] how to call drop down selected event from user control to aspx.cs in user define method.

查看:53
本文介绍了如何在用户定义方法中调用从用户控件下拉选定的事件到aspx.cs。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调用acsx.cs下拉的selectedindexchange事件到aspx.cs.

我的场景是这样的。



在我的用户控制中,有2个用于区域,第二个用于城市。我从用户定义功能public void FillAddress()设置aspx.cs的分区下拉值。在下一行之后,我想调用区域下拉列表的selectedindexchange事件来填补城市下拉。



我尝试各种代码,但我的需求id公开呼叫事件void FillAddress()方法。







提前致谢

How to call the selectedindexchange event of drop down of acsx.cs to aspx.cs.
My Scenario is like this.

On my user control there is 2 drop down one for district and second for city. i m setting value of district dropdown from aspx.cs from user define funtion public void FillAddress(). after that in next line i want to call the selectedindexchange event of district dropdown to fill the city drop down.

I try various code but my requirement id call event in public void FillAddress() method.



Thanks in advance

推荐答案

没有呼叫事件之类的东西。你处理事件;将事件处理程序添加到某个事件实例的调用列表中(+ =操作)。



事件可以调用,这意味着调用列表中的所有事件处理程序。但是没有办法调用你想要调用的事件;即使您创建了一个从下拉类派生的类,也无法执行此操作。根据定义,只能在声明此事件的类中完成对事件实例的调用。与常规委托实例相比,这是事件的限制之一。实际上,这只是重要的全面防范功能



这绝不是一个实际问题,因为这实际上并不需要。你真的不想调用选择事件;实际上,你只想获得与选择产生的效果相同的效果,这是不一样的。



让'考虑到你提到的, SelectedIndexChanged

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged.aspx [ ^ ]。



第一种方法是简单地选择你需要的物品。使用属性 SelectedIndex 。为其选择一个值以选择元素。在这种情况下,如果将事件处理程序添加到此事件的调用列表中,则会调用它。请参阅: http://msdn.microsoft.com/en-us /library/system.web.ui.webcontrols.dropdownlist.aspx [ ^ ]。



现在,让我们假设更奇怪的情况:你想要的编写一些在选择元素时发生的效果,但在其他地方执行,而不实际选择元素。在这种情况下,只需编写一个实现您的操作的单独方法。在代码的两个(或更多)位置调用它:在选择处理程序和其他位置。



-SA
There is no such thing as "call event". You handle events; add an event handler to the invocation list of some event instance (+= operation).

An event can be invoked, which means that all the event handlers from the list are called. But there is no a way to invoke the event you want to invoke; you cannot do it even if you create a class derived from your drop down class. By definition, invocation of the event instance can be done only in the class declaring this event. This is one of the limitations of the events, compared to "regular" delegate instances. Actually, this is just the important full-proof feature.

And this is never a practical problem, because this is never actually needed. You don''t really want to invoke the event of selection; in reality, you only want to have the same effect as the one caused by selection, and this is not the same.

Let''s consider the even you''ve mentioned, SelectedIndexChanged:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged.aspx[^].

First approach is to simply select the item you need. Use the property SelectedIndex. Assign a value it to select an element. In this case, if you add an event handler to the invocation list of this event, it will be called. Please see: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.aspx[^].

Now, let''s assume more weird situation: you want to program some effect that happens when you select an element, but do it elsewhere, without actual selection of an element. In this case, simply write a separate method implementing your action. Call it in two (or more) places of the code: in the selection handler and elsewhere.

—SA


这篇关于如何在用户定义方法中调用从用户控件下拉选定的事件到aspx.cs。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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