C# 向面板控件添加简单文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12863607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 00:44:10  来源:igfitidea点击:

Add simple text to panel control

c#asp.net

提问by

I have a panel in C#:

我在 C# 中有一个面板:

    Panel aspPanel = new Panel();
    Button aspbutton = new Button();
    aspbutton.Text = "Download PDF";
    aspbutton.Click += initDownload;
    aspPanel.Controls.Add(aspbutton);`

I have added Attributes and buttons and all kinds of cool dynamic stuff. But I want to just add simple text and so far am unsuccessful.

我添加了属性和按钮以及各种很酷的动态东西。但我只想添加简单的文本,到目前为止还没有成功。

I'm looking for how to add text behind the button. In the end the HTML code would render something like:

我正在寻找如何在按钮后面添加文本。最后,HTML 代码将呈现如下内容:

    <input type="button"/> Hello, this is a button, please click

Can someone point me in the right direction?

有人可以指出我正确的方向吗?

采纳答案by xandercoded

To add Literaltext after the button:

Literal在按钮后添加文本:

Panel aspPanel = new Panel();
Button aspbutton = new Button();
aspbutton.Text = "Download PDF";
aspbutton.Click += initDownload;
aspPanel.Controls.Add(aspbutton);

aspPanel.Controls.Add(new LiteralControl("some more text!"));

回答by codingbiz

Try this

尝试这个

Label lbl = new Label();
lbl.Text = "Hello, this is a button, please click";
aspPanel.Controls.Add(lbl);