title: Send a variable from a JavaScript script inside my ASP.NET page to a C# Function in Code-Behind
body: <p>I have my ASP.NET C# Web site and i have some JavaScript script inside one of my pages, i already succeeded in calling a C# function from my Code Behind but i want to send some variable from my JavaScript script as an argument of the function.</p>
  
  <p>Here is my code, including the C# function call:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function () {
          // Declare a proxy to reference the hub.
          var chat = $.connection.chatHub;
          // Create a function that the hub can call to broadcast messages.
          chat.client.broadcastMessage = function (name, message) {
              // Html encode display name and message.
              var encodedName = $('&lt;div /&gt;').text(name).html();
              var encodedMsg = $('&lt;div /&gt; ').text(message).html();
              var tremp_id = $('&lt;div /&gt; ').text("&lt;%=Request.QueryString["trempid"]%&gt;").html();
  
              // Add the message to the page.
              $('#discussion').append('&lt;li class="&lt;%=returnLiClass()%&gt;&lt;strong&gt;' + encodedName
                  + '&lt;/strong&gt;:&amp;nbsp;&amp;nbsp;' + encodedMsg + "Tremp:" + tremp_id + '&lt;/li&gt;');
          };
          // Get the user name and store it to prepend to messages.
          $('#displayname').val('&lt;%=returnName()%&gt;');
          // Set initial focus to message input box.
          $('#message').focus();
          // Start the connection.
          $.connection.hub.start().done(function () {
              $('#sendmessage').click(function () {
                  // Call the Send method on the hub.
                  chat.server.send($('#displayname').val(), $('#message').val());
                  // Clear text box and reset focus for next comment.
                  $('#message').val('').focus();
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>As you can see I'm calling the 'returnLiClass()' function (line 13) and i want to send the 'encodedMsg' var inside it.</p>
  
  <p>How can i do it? Thanks!</p>