如何创建我可以从用户控件(ascx)调用的属性字段和方法

时间:2022-05-02 22:50:21

I have made a basic ascx control which is just a panel with a couple controls. My question is how can I create custom properties I could set for my custom control? (I mean such as custom properties like runat, CssClass, etc...) I would also like to be able to create methods for my ascx that I could call. I tried putting public static methods in the asc code behind file, but that's not working.

我做了一个基本的ascx控件,它只是一个带有几个控件的面​​板。我的问题是如何创建我可以为自定义控件设置的自定义属性? (我的意思是像自定义属性,如runat,CssClass等...)我也希望能够为我的ascx创建方法,我可以调用它。我尝试将公共静态方法放在asc代码后面的文件中,但这不起作用。

Any help is appreciated.

任何帮助表示赞赏。

1 个解决方案

#1


The attributes you can add to your user control are simply properties in your code-behind. See Microsoft's crash course on building custom user controls.

您可以添加到用户控件的属性只是代码隐藏中的属性。请参阅Microsoft关于构建自定义用户控件的速成课程。

#1


The attributes you can add to your user control are simply properties in your code-behind. See Microsoft's crash course on building custom user controls.

您可以添加到用户控件的属性只是代码隐藏中的属性。请参阅Microsoft关于构建自定义用户控件的速成课程。