MrM
MrM

Reputation: 21989

What is the correct way to show text in a button?

How do I display text for a button without going between the <button></button> tags?

<button id="btnTest" >Need Text in button tag!</button>

Upvotes: 0

Views: 183

Answers (3)

soniiic
soniiic

Reputation: 2685

You should use the input tag. The benefit of this is that the value of the button is also passed to the server along with the the contents of the form. This way on the server you can determine which button was pressed on the form. So say for example, you had a submit and a delete button. They would both be inputs with a type of 'submit' but their values would differ and so when it posts back, you can check the value of btnSubmit

Just remember that

<input type="submit" id="btnSubmit" value="text here" />

and

<button type="submit" id="btnSubmit">text here</button>

will look different so you don't want to mix the two in the same form :)

Upvotes: 0

&#199;ağdaş Tekin
&#199;ağdaş Tekin

Reputation: 16651

I think you may have meant to ask for this :

<input type="submit" value="Text on button" />
<input type="button" value="And again" />

Upvotes: 3

Rob
Rob

Reputation: 711

If you're doing it in ASP.net, use the asp button:

<asp:Button id="btnTest"
           Text="Need Text In button Tag"
           OnCommand="CommandBtn_Click" 
           runat="server"/>

Upvotes: 1

Related Questions