How to call two functions for one event. one as a javascript function, the other server-side function

I want to call two functions on one event 1 on the client side and the other 1 on the server side. How can i do this

 <input type="text" ID="txtUserName" runat="server" maxlength="50"
                            class="DefaultTextbox" style="width:180px;" value="" 
                            onfocus="ControlOnFocus('', this, spanUserName);"
                            onblur="ControlOnBlur('',this, spanUserName); "
                            />

onblur = "ControlOnBlur (); function2 ();

Is it correct?

onblur="ControlOnBlur(); function2();
+3
source share
3 answers

Correctly. This is actually not a good practice to define events embedded in HTML, but it works. Everyhing between "and" in is onblur=""considered as one long block of JavaScript code, so you can write anything in it, even your entire program, if you want.

onblur="sentence1; sentence2; sentence3;"
+3
source

-, , __doPostBack (this.name, '') ( , (GetClientResourceUrl, ), __doPostBack .

MVC, $.get $.post, $.get( "/Controller/Action", function (result) {}). - . - .

+1

The closest you can get is to call a local function (javascript) and then turn off the server request through an asynchronous call (Ajax). However, you cannot directly call the method on the server from the client.

Using jQuery, it will look like this:

$("#txtUserName").blur(function(e){
  ControlOnBlur(); // call first function
  $.post("/methods", {methodName:"refreshData", function(results){
    /* results represents that which was returned from the server */
    alert(results);
  });
});
0
source

Source: https://habr.com/ru/post/1727877/


All Articles