Asp.net codebehind from javascript?

前端 未结 3 1807
野趣味
野趣味 2021-01-21 03:34

Is it possible to call asp.net codebehind function from javascript in vs2008?
My problem is, I have two codebehind methods, one is for some validation and it will return tru

3条回答
  •  难免孤独
    2021-01-21 04:01

    To call a server side method on a client side event you need to do the following:

    1- Create the server side method:

    void DoSomething(...) { ... }
    

    2- Implement the System.Web.UI.IPostBackEventHandler.RaisePostBackEvent which take one string argument (You can assign the name to the value of this argument).:

    public void RaisePostBackEvent(string eventArgument) 
    {
            DoSomething(...);
    }
    

    3- Write a script to trigger post back:

    function TriggerPostBack(control, arg){
        __doPostBack(control, arg);
    }
    

    4- Call the PostBack trigger function when needed:

     
    

提交回复
热议问题