自定义服务器控件:在 ASPX 代码上以声明方式指定事件
我目前正在开发几个自定义 ASPX 服务器控件。 当然,这些控件也公开事件。 现在一种可能性是在代码中注册一个处理程序,更具体地说是在自定义服务器控件所在的页面中...例如
protected void Page_Load(object sender, EventArgs e)
{
myCustomControl.Click += new ....
}
但是我如何必须在我的服务器控件代码中公开该事件我可以直接声明这些事件处理程序ASPX 代码(来自属性编辑器),类似于您可以在按钮的单击事件上执行的操作?
非常感谢,
朱里
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你这样做...
如果你的 ASCX 控件上有一个名为 PropertyChanged 的公共事件,
那么它将在你的控件上以声明方式可用,如 OnPropertyChanged
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
您是否尝试过将它们设为公共活动?
Have you tried just making them public events?
这篇 MSDN 文章很好地解释了如何做到这一点,不幸的是它比看起来应该的更复杂。
[1]:http://msdn.microsoft。 com/en-us/library/aa719907(VS.71).aspx/“.NET Framework 开发人员指南”
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"