在ASP.NET页面中控制属性? [英] Control attributes in asp.net page?

查看:58
本文介绍了在ASP.NET页面中控制属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为控件创建自定义属性,并可以在我的asp.net页面中访问它.我需要做的就是存储一个简单的字符串,并将其值显示在我的asp页面中(为清楚起见).

我正在做的一个示例是使用验证控件,我需要两个值.第一个值是使用错误消息"(Error Message)属性在控件页面上显示的值.然后,我遍历控件以创建包含详细信息的摘要文本文件.我目前正在使用工具提示字段来存储详细信息.

ErrorMessage =必需"
ToolTip =您遇到的验证错误..."

然后

对于每个验证人...
如果(!validator.IsValid)
...连接ToolTip + CHAR(13)...

我想创建可以在asp页面中设置的其他属性,例如:

< asp:textbox id = ... runat = ... MyAttribute1 = ... MyAttribute2 =

我知道我可以使用.attribute集合从C#管理自定义属性,但是这些属性在asp页中不可用(从我所看到的).我还看到了(有点)在带有重写的类上使用[Attribute ...]的复杂方法.这两种方法对于我的需求来说似乎都很复杂.

THanks

I am trying to create a custom attribute for a control and have access to it in my asp.net page. All I need to do is store a simple string and have its value visable in my asp page (for clarity).

One example of what I am doing is using a validation control and I need two values. The first value is what is displayed on the page for the control using the "Error Message" attribute. I then iterate through the controls to create a summary text file with detailed info. I am currenty using the tooltip field to store the details.

ErrorMessage="Required"
ToolTip="The validation error you have encountered..."

then

for each validator...
if (!validator.IsValid)
... concatenate ToolTip + CHAR(13)...

I would like to create additional attributes I can set in the asp page like:

<asp:textbox id=... runat=... MyAttribute1=... MyAttribute2=

I know I can manage custom attributes from C# using the .attribute collection, but the attributes are not available in the asp page (from what I have seen). I have also seen (somewhat) complex approaches using [Attribute... on classes with overrides Both approaches seem complex for my needs.

THanks

推荐答案

嘿,请查看这篇文章,其中我使用我的自定义属性创建了自定义控件,并在我的javascript中使用了我的

希望这对您有帮助

hey check this articles which in which i have created custom control with my custom attributes and used by me in my javascript

hope this will help

<a href="http://www.codeproject.com/KB/aspnet/RequiredField.aspx">Generic Code of Validating Fields with Jquery</a>

<a href="http://www.codeproject.com/KB/validation/MyTextBox.aspx">Enhanced Textbox Control</a>


您不能使用ViewState?!?!?!?................... ..
u cant uses ViewState?!?!?!?.....................


这篇关于在ASP.NET页面中控制属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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