Wrap text within a asp:Button

I was using a LinkButton and it had like lot of text in it which made it quite long. This was fine as the LinkButton wrapped the text onto the next line when it ran out of room.

I then changed this to a standard asp:Button and the problem is the text doesn’t wrap the button just becomes as long as the text. This is a problem because it forces the container it is within to be longer than I intended.

Is there a way to make the text of the button wrap?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can do that by setting a width and the CSS property white-space: normal:

This goes in your <head>

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

And your button:

<asp:Button ID="btn" runat="server" Text="some really breally long text that I want to wrap" CssClass="wrap" />

Method 2

<asp:Button ID="btn" runat="server" Text="some really breally long 
 text that I want to wrap"  />

This question was helpful and wanted to point out if we want to break the text in a specific spot we could also by adding the
within the text value.

I also marked wsanville answer as useful.

Method 3

You should be able to set a width on the asp:button (width=100) and that should force the text to wrap.

Method 4

There are some alternate solutions in this post that may be helpful:

ASP:Button Text Word Wrap


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x