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

I have a button in my project, the text of which I set via the aspx.cs page. Here is the button code

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

      

Here is the code from the aspx.cs page

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

      

I need the word "Summary", which will appear on the next line. I tried to use <br />

, \n

as well as the ASCII value for <br />

and \n

, but no luck.

+3


source to share


2 answers


EDIT: as pointed out in the comment, this solution may not work in some browsers, please use CSS to achieve this as suggested here

declare this CSS class:

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

      

Then in code:

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

      



This may work in some browsers,

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

      

[ampersandHash010;] a character entity usually gives a newline in the button text. Please refer to this link for more symbol references:

Hope it helps.

+1


source


You can try this CSS:

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

      

Exact text for the button:



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

      

NOTE : spaces before and afterEnvironment.NewLine

0


source







All Articles