English 中文(简体)
3. 开展定制活动,使网络用户能够相互控制
原标题:raising custom events to allow web user controls to intercommunicate
  • 时间:2010-04-02 20:45:05
  •  标签:
  • c#
  • asp.net

我有2个网络用户控制,两者都继承了相同的基类,即用户控制。 我想就一个事件提出,而另一个事件应该知道。 这两条都在同一个网页上,但第2条控制从未处理过第1条中提出的习俗事件! 是否有任何想法? 仅请说明可能的实施情况(BTW,自早起就把它ling起来,但不要 l!)

最佳回答

你可以很容易地做以下工作:

1) create an event in control 1.
2) create a public method in control 2, that gets called if the event in control 1 is raised
3) subscribe to the event of control 1 (where you instanciate them, e.g. another control, a content page or a master page)
4) inside the event handler from 3), call the method created in 2)

5)如果控制2与控制1进行沟通,则采取其他行动

所有这一切都需要在服务器上安装。 我确信,也可能有客户方的解决办法。

Edit after comment: There are only two possible communication ways I can think of:
1) the controls don t know each other and therefore can t communicate directly. => you need a third control/page/masterpage/whatever (database, service etc) to enable the communication
2) the controls reference each other and therfore can communicate directly => very bad OOP. If you use this, you do not understand OOP at all and should consider your job

自由地选择其中一种选择。

问题回答

你们可以通过使用代表的用户控制组织举办活动。

http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/Easily-Raise-Events-From-ASP.NET-ASCX-User-Controls.aspx” rel=“nofollow noreferer”>Here





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签