Gaurav123
Gaurav123

Reputation: 5209

How to change the value of type attribute in asp.net?

I have asp.net server side button. I want to change the value of type attribute from submit to button.

Button :

Currently I used the below code to change the value of type attribute

 var submitForm = "<%=submitForm.ClientID %>";
 $('#' + submitForm).attr("type", "button");

but I found below error : uncaught exception: type property can't be changed

How can I change the value?

Upvotes: 1

Views: 917

Answers (2)

EdSF
EdSF

Reputation: 12341

The answer works, but seems there is another (perhaps more fundamental) question - why even go that route? If you needed a "regular" button, then use a standard html button or a server side HTML button:

If you just want to have a button to script client side:

<input type="button".... /> instead of <asp:button....

If you want the 'best of both worlds' use a "server HTML control":

<input type="button" runat="server"...../>

Unsure what you were after, but sometimes it pays to take a step back and take another look....

Upvotes: 1

Kamran Pervaiz
Kamran Pervaiz

Reputation: 1931

please try below code

$('#' + submitForm).prop("type", "button");

http://jsfiddle.net/qeUxP/

Upvotes: 3

Related Questions