Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass code behind variable value to jQuery function

I am not an expert in jQuery and I am trying to pass some variable values from C# to my function called on keyup and onclick events. So far I have something like this:

$('mydiv').bind('keyup click', function(event) {}

but what I need should be:

$('mydiv').bind('keyup click', function(event, UserId, ControlId) {}

, where UserId and ControlId are some ids I am getting in code behind from the query string. I am also using jQuery 1.6.4.

How can I do this, preferably without using hidden input fields? Thank you.

like image 599
Crista23 Avatar asked Nov 27 '22 16:11

Crista23


1 Answers

Use on instead of bind

As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document.

Passing values from the server to the client with razor (if youre using asp.net mvc):

$('mydiv').on('keyup click', function(event, @UserId, @ControlId) {}

or if its webforms:

$('mydiv')
    .on('keyup click', function(event, <%= UserId %>, <%= ControllId %>) {}
like image 144
Johan Avatar answered Nov 29 '22 06:11

Johan