jquery - html button elemenents and onserverclick attribute in asp.net -
I am experiencing some very strange behavior using the html button with the onserverclick attribute. What I'm trying to do is to use jQuery to specify the default button on the page. With the default button, I mean "clicked" on that button when a user enters a hit. In the trial, I was killed during an input field and sometimes the "default" button was clicked and defined on the server in such a way that the on-the-fly-specific feature was defined. The second time a post was created without killing the server system back. To separate this issue, I made a case of minimum testing and saw some very interesting results.
Client Side:
& lt; Html xmlns = "http: // www .w3.org / 1999 / xhtml" & gt; & Lt; Head runat = "server" & gt; & Lt; Title & gt; Untitled Page & lt; / Title & gt; & Lt; Script type = "text / javascript" src = "/ script / jquery-1.4.min.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; Asp: Label ID = "_response" runat = "server" & gt; & Lt; / Asp: label & gt; & Lt; Input ID = "Input 1" type = "text" / & gt; & Lt; Input id = "input2" type = "text" / & gt; & Lt; Button id = "first" type = "button" class = "defaultbtn" runat = "server" onsourceclick = "server math1" & gt; Test1 & lt; / Button & gt; & Lt; Button id = "second" type = "button" runat = "server" onserverclick = "ServerMethod2" & gt; Test2 & lt; / Button & gt; & Lt; / Form & gt; & Lt; Script type = "text / javascript" & gt; JQuery ('form input'). Keyboard (function (e) {if ((e.wich and e.which == 13) || (e.keycode & e.keyCode == 13)) {$ ('Button.defaultBtn'). Click (); back to true;}}); & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Server side:
public partial class admin_spikes_ButtonSubmitTest: System.Web.UI.Page {secure void page_load (object sender, EventArgs e) {} protected Zero ServerMethod1 (Object Sender, EventArgs e) {_response.Text = "Server Method 1 Hit"; } Secure Zero ServerMethod2 (Object Sender, EventArgs e) {_response.Text = "Server Method 2 Hit"; }
}
I came to know that whenever I removed one of the input elements, all this worked as expected with this code. In Firefox 3.6 and IE8, when there is only one input on the page, the anuswerver does not click by pressing Enter, it returns the post without having "clicked" or "clicked" without jQuery, you start with two inputs You can test it by clicking on "test2" and "sur And Method 2 will hit "output. After that simply enter the hit and the output "server meth1 was killed. Now remove an input and run the same test." Click on Test 2 "to see results, then enter and you will see that" test1 "
- document "itemprop =" text ">
try this:
jQuery ('form input'). Key (function (e) {if ((e.which & amp; E.which == 13) ((e.keycode & e.keycode == 13)) {$ ('#__ EVENTTARGET'). Val ($ ('DefaultBtn'). Attr ('name')); Document.forms [0]. Submit (); Return;}});
You can use the attribute of:
asp: form runat = "server" id = "form1" default button = "first" & gt; ... & lt; / Asp: form>
Comments
Post a Comment