Using Inner HTML with an ASP:Button?
Asked Answered
H

2

5

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.

Hostility answered 30/11, 2011 at 7:28 Comment(0)
S
1

If you really need rich formatting either you use a css class and define all styling in the css side or you can use an html anchor

I am not aware of another way to compose the inner html of a button or linkbutton like you are trying to do.

Shipway answered 30/11, 2011 at 7:44 Comment(0)
M
8

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

Mayolamayon answered 26/7, 2013 at 10:24 Comment(1)
is there a way to do this for the <asp:Button> and the <asp:Menu>? Even a programmatical solution would be nice, I am trying to use twitter bootstrap in my current asp.net project and this is the best way i have seen so far. But it doesnt help me because i am using asp:Button instead.Livelihood
S
1

If you really need rich formatting either you use a css class and define all styling in the css side or you can use an html anchor

I am not aware of another way to compose the inner html of a button or linkbutton like you are trying to do.

Shipway answered 30/11, 2011 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.