Okay, this may seem silly, but on an ASP.NET .ascx control, I'm trying to use:
<input type="button" runat="server" />
instead of:
<asp:Button runat="server" />
And it's not working for me. This code:
<asp:Button id="btnBuyCat" runat="server" Text="Buy Cat"
ToolTip="Click to buy a cat" OnClick="btnBuyCat_Click" EnableViewState="false" />
renders the following HTML: (ignoring naming containers btw)
<input type="submit" id="btnBuyCat" name="btnBuyCat" value="Shopping Cart"
title="Click to buy a cat" />
That's mostly fine, except I want input type="button"
not input type="submit"
.
I tried this code:
<input type="button" id="btnBuyCat" name="btnBuyCat" runat="server"
value="Buy Cat" title="Click to buy a cat" onclick="btnBuyCat_Click"
enableviewstate="False" />
and get this HTML:
<input type="button" id="btnBuyCat" name="btnBuyCat"" value="Buy Cat"
title="Click to buy a cat" onclick="btnBuyCat_Click" />
Unfortunately the rendered button does not work. Also, I even tried input type="submit"
just to check, but unless I use the <asp:Button>
I can't get it to work. I'm sure it has something to do with the JavaScript.
Is there a way to use the regular HTML button markup and a runat="server"
in ASP.NET?
What you're missing is the UseSubmitBehavior
attribute, e.g.,
<asp:Button id="btnBuyCat" runat="server" Text="Buy Cat"
UseSubmitBehavior="False" ToolTip="Click to buy a cat"
OnClick="btnBuyCat_Click" EnableViewState="false" />
This will give you a regular button, not a submit button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With