user3071591
user3071591

Reputation: 83

want to clear textbox + focus textbox + prevent asp.net postback on the same button

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

Answers (1)

Reza Owliaei
Reza Owliaei

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

Related Questions