Call jQuery function from ASP.NET code behind C#

前端 未结 2 926
陌清茗
陌清茗 2021-01-07 10:06

I have the following jquery function

> 

        
相关标签:
2条回答
  • 2021-01-07 10:37

    This doesn't make sense really. Your C# code runs on the server to generate an HTML file which is passed to the client and translated there. jQuery can only operate on the HTML n the client side.

    Is what you're trying to do not achieved by replacing

         $('#callGrowel').click(function() {
             $.growlUI('Email Received', 'from Joe Bloggs');
         });
    

    with

         $.growlUI('Email Received', 'from Joe Bloggs');
    

    ?

    0 讨论(0)
  • 2021-01-07 10:47

    I've use following way and for me work 100% properly:

    the first i create a function and write my jquery function in to the function in the my page:

    <script>
    function myFunction(params) {
        $.my_jquery(params...)
        ......
    }
    

    then i used this code in event handler of my control(for example click a button) who my control is inside a update panel:

    protected void myButton(object sender, EventArgs e)
    {
        .....
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>myFunction(params...);</script>", false);
    }
    

    successful

    0 讨论(0)
提交回复
热议问题