开发者

How to manually set button input type in ASP.NET?

开发者 https://www.devze.com 2023-01-01 16:24 出处:网络
I have a jQueryUI dialog with some textboxes, plus a button. Right now, the asp:Button tag use开发者_开发技巧d to generate the button automatically sets its type as type=\"submit\". The structure of t

I have a jQueryUI dialog with some textboxes, plus a button. Right now, the asp:Button tag use开发者_开发技巧d to generate the button automatically sets its type as type="submit". The structure of the dialog is such that pressing enter at any of the textboxes should not call the button click event. It seems like the cleanest way to solve the problem, if it is doable, is to manually set the button's type to something other than submit. Is there a way to do this?

Edit: Forgot to mention this, but the button text is bound to a database item by <%# Eval() %>, which doesn't work without a server-side tag.


" UseSubmitBehavior="false" OnClientClick="return" />

The UseSubmitBehavior property tells ASP.NET to render as type="button" and inserts a __doPostBack() function call into the onclick property. The text of the OnClientClick property gets prepended to the client-side onclick event (with a trailing semicolon if you don't include it yourself), therefore putting return simply short-circuits the event handler and ends up doing nothing at all.


You can use just a regular html button and set it to whatever you want. It doesn't have to be a serverside asp button.

In your aspx file:

<input type="button" value="My Button" onclick="DoSomeScript();" />


I don't think you can set the Button control's AutoPostBack to false, which would normally do what you want.

In this case, I would simply not use asp:Button and just use <input type='button'>.

0

精彩评论

暂无评论...
验证码 换一张
取 消