控件的属性,例如样式属性 [英] Control's attribute like style attribute

查看:97
本文介绍了控件的属性,例如样式属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
晚上好.

我正在控制自己,因为我添加了一个属性.
我希望该属性类似于Web控件的样式属性.

类似地,我想要一个带有子属性的属性.
例如:< crt:mycontrol id ="crt" newattribute ="subattribute:value; subattribute2:true"></crt:mycontrol>

因此,通过上面的示例,我想在控件中将样式属性(style ="width:30; height:50;")添加为"newattribute"的所有对象都将很清楚.

可能吗.如果是,那怎么办?请举例说明...
在此先感谢....

Hello everybody,
Good Evening.

I''m making my control in that i have added an attribute.
I want that attribute similar to style attribute of web controls.

By similar I mean, I want an attribute with its sub-attributes.
eg: <crt:mycontrol id="crt" newattribute="subattribute:value; subattribute2:true"></crt:mycontrol>

So, by above example it will be clear to all that i want to add ''newattribute'' in my control as style (style="width:30; height:50;") attribute.

Is it possible. If yes, then how? Please explain with examples...
Thanks in advance....

推荐答案

如果您逐步阅读此教程-
If you look at this step by step tutorial - Extending ASP.NET Web Controls With Custom HTML Attributes[^], you can see how you can create a new custom properties for your control.




我为你尝试了一些东西

一次检查一次

首先创建一个具有以下详细信息的Web用户控件

Hi,

I tried something for you

check this once

First of all create one web usercontrol with following details

<![CDATA[<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>]]>
 <div id="residv" runat="server" style=" background-color :Blue;"></div>



文件后面的代码包含以下代码



And code behind file contains following code

private  String styl;
public string Styl
{
    get { return styl; }
    set { styl = value; }
}

private string text;
public string Text
{
    get { return text; }
    set { text = value; }

}
protected void Page_Load(object sender, EventArgs e)
{
    residv.InnerHtml = text;
    string[] artlst = styl.Split(';');
    foreach (string g in artlst)
    {
        if ((g.Split(':'))[0].ToString() == "width")
        {
            residv.Style.Add(HtmlTextWriterStyle.Width, (g.Split(':'))[1].ToString());
        }
    }
}



最后是由该控件组成的测试页面



And finally testing page which consists of that control

<uc1:webusercontrol id="WebUserControl1" styl="width:500px;heigth:300;" text="Hi this is Testing" runat="server" xmlns:uc1="#unknown" />




然后,您可以将其开发为其他属性或您的自定义属性

最好的




Then you can develop this for further properties or your custome properties

All the Best


这篇关于控件的属性,例如样式属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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