English 中文(简体)
ASP.NET的HtmlTextArea属性和换行符
原标题:ASP.NET HtmlTextArea attributes and newline

我想在我正在用C#开发的SharePoint网络部件中更改HtmlTextArea的一些属性。 HtmlTextArea被用作一些我正在获取的Sql Server 2005数据的自定义显示,并且我想更改字体,颜色等,并使其只读。我看到有一些方法,例如HtmlTextArea.Attributes.Add,HtmlTextArea.Attributes.AddAttributes和HtmlTextArea.Attributes.CssStyle,但我不确定这些是否是正确的方法,也不知道如何使用它们。我知道对于ASP.NET TextArea控件,我可以简单地使用内联CSS,因此我正在尝试找出一种从C#中设置该内联CSS的方法。

此外,我希望找到一种方法在控件之间添加换行符,以便于布局。我已经在CreateChildControls中布置了所有控件,但我不知道如何控制它们的位置。例如,我有如下内容:

    protected override void CreateChildControls()
    {
        customers = new DropDownList();
        customers.ID = "customers";
        Controls.Add(customers);

        machines = new DropDownList();
        machines.ID = "machines";
        Controls.Add(machines);

        specsOutput = new HtmlTextArea();
        specsOutput.ID = "specsOutput";
        Controls.Add(specsOutput);
    }

我希望HtmlTextArea在下拉列表框下面显示。感谢大家的帮助。

最佳回答

要添加内联 CSS,请使用 Attributes.Add("style", "color: white; background-color: black"); 等等。

您可添加<代码>LiteralControls,以协助您进行海关管制。

customers = new DropDownList();
customers.ID = "customers";
Controls.Add(customers);
Controls.Add(new LiteralControl("<br />"));
问题回答

要管理控件的呈现方式,可以重写Render事件,如下所示:

protected override void Render(HtmlTextWriter writer)
{
    customers.RenderControl(writer);
    writer.Write("<br />");
    machines.RenderControl(writer);
    writer.Write("<br />");
    specsOutput.RenderControl(writer);
}

正如 womp 所提到的,可以通过在控件上使用 Attributes.Add 方法来添加内联样式。

如果你想摆脱这种相当笨拙的构建Web部件UI的方式,你可以加载一个ASCX,你的Web部件设计体验将像任何用户控件一样..好得多。

示例





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签