Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Inner HTML with an ASP:Button?

How can I convert

<button type="submit" class="blue">
<span>Login</span>
</button>

Into an asp button?

<asp:Button ID="Button1" runat="server" Text="Button" />

<asp:LinkButton ID="LinkButton1" runat="server" CssClass="blue"><span>Login</span></asp:LinkButton>

I just simply cannot find a way to do it. Sorry its a crappy question, but it's throwing me for a loop, might just need to sleep on it.

like image 666
Landmine Avatar asked Nov 30 '11 07:11

Landmine


People also ask

Why innerHTML does not work?

People can struggle and complain about innerHTML not working. Such things usually occur because of human error, when strings are not appropriately defined, or there are some mistakes in JavaScript code.

How do I put text on a button in HTML?

Inside a <button> element you can put text (and tags like <i> , <b> , <strong> , <br> , <img> , etc.). That is not possible with a button created with the <input> element! Tip: Always specify the type attribute for a <button> element, to tell browsers what type of button it is.

What is ASP LinkButton?

It is a server web control that acts as a hyperlink. It is used to display a hyperlink-style button control on the web page. ASP.NET provides a tag to create LinkButton and has following syntax.


1 Answers

I agree with Davide that CSS is the best solution but if you have some styling requirement which requires multiple tags then LinkButton is your best bet. You can apply all the styles you would to have put on 'button' tag on to the 'a' tag.

    <asp:LinkButton ID="submit" runat="server" OnClick="Submit_Click" CssClass="block-button">
        <span runat="server" ID="submitText" ClientIDMode="Static" class="block-button-text">Submit</span><span class="block-button-arrow">&nbsp;</span>
    </asp:LinkButton>

If you really must have a button tag then the only way is to create a custom control that implements all the functionality of asp:button

See here for a solution by prabhakarbn http://forums.asp.net/t/1496938.aspx/1

like image 72
Grazerbeam Avatar answered Oct 26 '22 00:10

Grazerbeam