• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

jquery onclick and server side.

Trying use a jquery onclick event and serverside button submission one work without the other. need both to work at the same time.

  $(document).ready(function () {
           $('[id$="txtSubmit"]').each(function (index, button) {
           var oldClickHandler = button.onClick;
           $(button).click(function (clickEvent) {
alert("work");
   oldClickHandler.call(button, clickEvent);
           });
       });
       });

Open in new window


<asp:Button runat="server"    ID="txtSubmit" Text="Next" />
 Protected Sub txtSubmit_Click(sender As Object, e As EventArgs) Handles txtSubmit.Click
function work here
response.write("function started")
End sub
0
Seven price
Asked:
Seven price
  • 2
1 Solution
 
Michel PlungjanIT ExpertCommented:
IDs MUST be unique so either use a class or if you only have one button, remove the each and have

$(document).ready(function () {
  var but = $("#txtSubmit"); // or $("<%= txtSubmit.ClientID %>");
  but.get(0)._onclick=but.get(0).onclick; // save the DOM onclick
  but.on("click",function (e) {
    alert("work");
     this._onclick.call(this, e);
   });
});

Open in new window

0
 
Seven priceFull StackAuthor Commented:
Well that is the funny part I use the id and it was unique and it worked then it just stopped working. Only the jquery works first and not the server side. Or if I remove the jquery then the client side work. crazy.
0
 
Seven priceFull StackAuthor Commented:
Thanks for the response I resolved everything to javascript and using document.elemenbyid.  on the server side passing values to hidden input textbox.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now