Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  150] [ 2]  / answers: 1 / hits: 36110  / 14 Years ago, tue, august 10, 2010, 12:00:00

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?


More From » asp.net

 Answers
26

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.


[#95976] Friday, August 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
moriah

Total Points: 201
Total Questions: 100
Total Answers: 82

Location: Tuvalu
Member since Sun, Sep 4, 2022
2 Years ago
;