在ASP.NET用户控件中使参数成为必需 [英] Making a parameter mandatory in an ASP.NET user control

查看:74
本文介绍了在ASP.NET用户控件中使参数成为必需的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有谁知道我是否可以向ASP.NET用户控件的代码隐藏文件中的属性添加属性,以使在页面中使用该控件时必须指定该值?我在某处看到了"[Required]"属性,但是智能感知对我在.ascx文件中使用它并不满意.
从更笼统的角度来看,任何地方都有很好的属性列表吗?在我看来,这似乎是一件妖术,发现可以在何时何地向代码添加哪些属性.

任何帮助将不胜感激.


亲切的祝福,帕特里克

Hi,

Does anyone know if there is an attribute I can add to a property in a code-behind file for an ASP.NET User Control to make it mandatory that the value is specified when the control is used in a page? I have seen the ''[Required]'' attribute somewhere but the intellisense doesn''t seem happy about me using it in a .ascx file.

On a more general note, is there a good list of attributes anywhere? It all seems a bit like a black art to me, finding what attributes can be added to code where and when.

Any help would be very much appreciated.


Kind wishes, Patrick

推荐答案

如果我正确理解的话:

为什么需要一些诸如required之类的属性.如建议的那样,您可以使用.Net inbuild requiredfield验证程序,也可以在服务器端属性的设置程序上进行验证.如果发现无效,则引发异常或显示一些消息.

如果我了解您的问题,例如:
在页面上注册用户控件时需要任何智能提示或帮助,它应该向开发人员说明必需的属性吗?

然后,我建议您在用户控件中包含一些预填充的属性.假设有人拖放用户控件,它应该使用一些预定义的值预填充您的属性.像
If I understood correctly:

Why you need some attribute like required. As suggested you can use .Net inbuild requiredfield validator or You can also make validation on your server side setter of your property. If you find invalid then throw exception or show some message.

If I understood your question like:
You want any intellicense or some help while registering the user control on page it should say required properties to your developer?

Then, I would suggest to have some prepopulatd properties in your usercontrol. Say the moment someone will drag and drop your user control it should pre-populate your properties with some pre-defined values. like
<uc:mycontrol requiredproperty1="someValue" requiredproperty2="someValue1" xmlns:uc="#unknown"></uc:mycontrol>

develepor至少可以看到所需的属性,并可以根据其要求更改值.

希望对您有所帮助.

In this way atleast develepor can see what are the properties required and can change the value according to their requirement.

Hope it helped.


您想要一个RequiredFieldValidator.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx [ ^ ]
You want a RequiredFieldValidator.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx[^]


这篇关于在ASP.NET用户控件中使参数成为必需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆