Custom server control: specifying event declaratively on ASPX code

[亡魂溺海] 提交于 2019-12-11 07:35:29

问题


I'm currently working on several custom ASPX server controls. Of course these controls do also expose events. Now one possibility is to register a handler in the code, more specifically in the page where the custom server control resides...like

protected void Page_Load(object sender, EventArgs e)
{
   myCustomControl.Click += new ....
}

But how do I have to expose the event in my server control code s.t. I can declare these event handlers directly on the ASPX code (from the Property Editor), similar as you can do it on the Button's click event??

Thanks a lot,

Juri


回答1:


You do just that...

If you have a public event on your ASCX Control called PropertyChanged

then it'll be available declaritively on your Control as OnPropertyChanged

<ctl:MyControl ID="abc" runat="server" OnPropertyChanged="abc_PropertyChanged" />



回答2:


Have you tried just making them public events?




回答3:


This MSDN article does a good job explaining how to do this unfortunately it is more complicated than it seems like it should be.

[1]: http://msdn.microsoft.com/en-us/library/aa719907(VS.71).aspx/".NET Framework Developer's Guide"



来源:https://stackoverflow.com/questions/768607/custom-server-control-specifying-event-declaratively-on-aspx-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!