开发者

Can you pass a delegate in as a server control parameter?

开发者 https://www.devze.com 2023-02-04 15:43 出处:网络
I have a server control that performs some logic.I\'d love to p开发者_高级运维rovide a default implementation of this logic in the code of the control, but allow a developer to pass an alternate imple

I have a server control that performs some logic. I'd love to p开发者_高级运维rovide a default implementation of this logic in the code of the control, but allow a developer to pass an alternate implementation of this logic in as a delegate, if they wish.

So...

<prefix:MyControl FooLogicMethod="MyUtilityClass.MyFooLogicMethod" runat="server"/>

If they don't specify this, I'll use my default method. If they do specify it, I'll use the method they passed in.

Can I do this as a delegate, or do I need to reflect it?


You can't do it like that... the asp.net compiler won't recognize the syntax, its pretty basic what kind of databinding you can do. Instead you can do it codebehind and setting the delegate like this

var control = someID;
control.FooLogicMethod = new Delegate(MyUtilityClass.MyFooLogicMethod);
0

精彩评论

暂无评论...
验证码 换一张
取 消