简体   繁体   English

如何在aspx.cs页面的C#中设置多行的按钮文本?

[英]How I can set button text on multiple lines in C# from aspx.cs page?

I am having a button in my project whose text I am setting through aspx.cs page. 我在我的项目中有一个按钮,我通过aspx.cs页面设置了它的文本。 Here is code of button 这是按钮代码

<asp:Button ID="btnEmailRequestSummary" runat="server" OnClick="btnEmailRequestSummary_OnClick" />

Here is code from aspx.cs page 这是aspx.cs页面的代码

if (//condition)
{
    btnEmailRequestSummary.Text = "Generate & Email - Request Summary";
}
else
{
    btnEmailRequestSummary.Text = "Generate Request Summary";
}

I need a 'Summary' word to be appear on next line. 我需要在下一行显示“摘要”字样。 I tried using <br /> , \\n , and also ASCII values for <br /> and \\n but no luck. 我尝试使用<br />\\n<br />\\n ASCII值,但没有运气。

EDIT : As pointed in comment this solution might not work on some browsers, please use CSS to achieve this as suggested here 编辑:正如评论中指出的,这个解决方案可能不适用于某些浏览器,请使用CSS来实现这一点

declare this CSS class : 声明这个CSS类:

<style type="text/css">
    .wrap { white-space: normal; width: 100px; }
</style>

Then in the code-behind: 然后在代码隐藏中:

btnEmailRequestSummary.Attributes.Add("class", "wrap ")

This might work on some browsers, 这可能适用于某些浏览器,

btnEmailRequestSummary.Text = "Generate Request &#010; Summary"; 

[ampersandHash010;] character entity normally gives the new line in Button Text. [ampersandHash010;]字符实体通常在Button Text中给出新行。 Refer this link for more Character Entity References: 有关更多字符实体参考,请参阅此链接

Hope this helps. 希望这可以帮助。

You may try this CSS: 你可以尝试这个CSS:

white-space: pre;
width: 60px;
word-wrap: break-word;

With the exact text for the button being: 使用按钮的确切文本:

string.Format("Generate & Email - Request {0} Summary", Environment.NewLine);

NOTE : the spaces before and after the Environment.NewLine 注意Environment.NewLine之前和之后的空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM