Click here to Skip to main content
15,906,569 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all
i have buttons with fixed size and the text of each is dynamically set
my problem: when the text is long , the button cuts it,
i want to make the long text in 2 lines and re-size it to fit the button automatically
my button code
ASP.NET
<asp:Button ID="btnSubCat1" runat="server" Text="Button" onclick="subCatClick"
                           Visible="False" Width="100px" Height="50px"/>

code behind:
C#
btnSubCat1.Text = dr["NAME"].ToString();
               btnSubCat1.Visible = true;
Posted
Comments
BELGIUMsky 27-Mar-14 10:35am    
Did you try using height auto?
M. Daban 27-Mar-14 10:41am    
!!! how to use it?
BELGIUMsky 27-Mar-14 10:49am    
Don't seem to find it again but maybe the solution to this question can help you out
wrap text within a aspbutton[^]
M. Daban 27-Mar-14 11:02am    
its work , thank you

AS addition to SA's solution…
You can use HTML entities inside the value property of the input tag to break line...
HTML
<input type="button" value="Some&#13;&#10;Text"/>
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 27-Mar-14 11:28am    
Yes, it will work, but I voted 4. I did not mention this possibility, because there is a problem with it. #13#10 is valid only for some platforms (Microsoft). In practice, it will work only because one of #13 or #10 will be ignored on other platforms, and the other character will be interpreted as end-of-line. This is just not a clean solution.

I credited it in my Solution 2, but see also my update to it, after [EDIT].

—SA
Kornfeld Eliyahu Peter 27-Mar-14 11:37am    
OT - my apologizes for that 'SAK' thing. Didn't know you don't like it (and didn't see you use SA only)...
Sergey Alexandrovich Kryukov 27-Mar-14 11:40am    
No problem at all. By the way, I use such a long form of my name (my official US name uses only the middle initial 'A'), because my official name I wanted to use from the very beginning was already busy as some other member name, of a totally inactive member. :-(
—SA
Kornfeld Eliyahu Peter 27-Mar-14 13:43pm    
We may kick him off for you? :-)
Sergey Alexandrovich Kryukov 27-Mar-14 14:07pm    
I don't think it would be appropriate thing to do, no... And people already know who am I...
—SA
There are at least to forms of button in HTML. In one form, you can use the break element to show more than one line:
HTML
<button>First Line<br/>Second Line</button>

If I'm not much mistaken, ASP.NET uses a different form of it (please check it up):
HTML
<input type="button" value="Some Text"/>

Even if ASP.NET uses the second form based on input element, you can use the first form, in order to have some multiline button text, and handle the click directly via Javascript. Or create your own ASP.NET control based on this HTML.

As a bonus, you will get understanding of how ASP.NET and ASP.NET controls really work. :-)

[EDIT]

Solution 3 will also work, but it is not quite clean one, even though in practice it probably (sic!) should work in all platforms. In my comment to it, I tried to explain why.
Please see: http://en.wikipedia.org/wiki/End_of_line[^].

—SA
 
Share this answer
 
v3
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900