c# - How to call two functions on single event. one as a javascript function other a server side function - Stack Overflow

admin2025-04-18  0

I want to call two functions on same event 1 is client side and other 1 is server side. How can i do that

 <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();

I want to call two functions on same event 1 is client side and other 1 is server side. How can i do that

 <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();
Share edited Jan 9, 2010 at 19:15 Shantanu Gupta asked Jan 9, 2010 at 19:06 Shantanu GuptaShantanu Gupta 21.1k56 gold badges186 silver badges293 bronze badges 1
  • i think this might help you ,[stackoverflow./questions/4524877/… – Emmanuel Angelo.R Commented Feb 5, 2014 at 10:22
Add a ment  | 

3 Answers 3

Reset to default 3

Thats correct. Actually it's not very good practice to define events inlined in HTML but it works. Everyhing between " and " in onblur="" is treated as one long JavaScript code block so you could write anything in it, even your whole program if you would like.

onblur="sentence1; sentence2; sentence3;"

If using web forms, you want to post back to the server to process a server-side event, you can use __doPostBack(this.name, '') to post back to the server (it was mentioned alternatively that you can use a server side event to output (GetClientResourceUrl I believe or named similarly) this, but I like to use the __doPostBack method to perform the postback.

If using MVC, you can invoke an action method using $.get or $.post as in $.get("/Controller/Action", function(result) { }). For web forms, you can't invoke a method directly. You can invoke a web service or page method.

HTH

The closest you can get is calling a local function (javascript), and then firing off a request to the server via an asynchrounous call (Ajax). You cannot directly call a method on the server from the client though.

Using jQuery, it would 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);
  });
});
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744949680a276256.html

最新回复(0)