views:

49

answers:

3

The following works just fine in Chrome.

<asp:LinkButton runat="server" ID="lbEdit" OnClick="lbEdit_Click">
    <button type="button" class="edit">
         Edit
    </button>
</asp:LinkButton>

And here is the CSS for button and its subclass.

button
{    
    padding: 3px;
}
button.edit 
{
    background:#3f6096;
    border:none;
    font:10px verdana;
    color:#fff;
    width:71px;
    margin-top:3px;
}

As you can see, nothing special; just colors and beautiful things.
I click on the blue Edit button and it fires the OnClick postback just fine.... in Chrome!
But if I do the same in IE8, it just does nothing; doesn't even detect a click.

To help pinpoint the problem, I removed the tag and kept just the word "Edit", and it works just fine in IE8 as a simple underlined link; the postback fires.

So, Why can't IE8 accept anything within LinkButton?

+3  A: 

Why use a LinkButton if you need to handle a postback and look like a button at the same time? Why not make it just a Button? It seems to me that the only reason to use one over the other is appearance. Functionally, they're both supposed to trigger a postback.

John Nelson
Not sure why I didn't see your answer before I posted. +1!
Andrew Barber
That did it for me; not sure why I started with LinkButton. Switching to Button and using the same CSS for it worked just fine. Thanks!
Beemer
A: 

What you are doing isn't something you are supposed to do, but I would say that IE is probably the one behaving closest to 'correctly' here.

You should not nest button elements inside other elements that provide links. You can simply remove the button from inside the LinkButton, attach the OnClick to it instead, make the styling work, and it'll be good.

The reason I say I think IE is behaving closer to 'correctly' is because it's doing what you have defined on the innermost tag; which is nothing. (you have not attached any actions to the button element, in actuality). But really, it's not something you should do in HTML anyway, as I don't think the behavior is defined in the first place.

Andrew Barber
A: 

What are you trying to achieve here?

You have a server-side link button, with a nested HTML button?

A LinkButton is useful when you want a hyperlink to be able to perform a postback.

Did you have a look at the rendered HTML? I don't know if having a button inside an anchor tag is even valid HTML.

If you want the postback to be handled by a particular server-side event, just use an ASP:Button.

If you dont, just use a regular HTML button.

RPM1984