Reputation: 83
I have this simple html button on ASP.NET, and on button click I want to clear textbox1, focus on textbox1 and prevent postback as well. How can I do this? Preventing postback also stops button's ability to clear and focus. Thanks.
$("#button1").click(function () {
var text1 = $("#textbox1").val();
$.connection.moveshapehub.server.sendmessage1(text1); //send text to hub
//want to clear textbox1 + focus on textbox1
return false; //prevent asp.net postback
});
Upvotes: 1
Views: 642
Reputation: 3363
$("#button1").click(function (e) {
e.preventDefault();
var text1 = $("#textbox1").val();
$.connection.moveshapehub.server.sendmessage1(text1); //send text to hub
//want to clear textbox1 + focus on textbox1
$("#textbox1").focus().val("");
return false; //prevent asp.net postback
});
Upvotes: 3