How do I pass data from c# to jquery/javascript?

后端 未结 5 608
情书的邮戳
情书的邮戳 2021-01-27 18:42

I have a function that I\'d like to run when the page loads, so either in document.ready or pageLoad.

Using jquery, I\'ll trigger the function using its class name

5条回答
  •  臣服心动
    2021-01-27 19:29

    Another possible way of doing this is to write the javascript function at page load in your C# code. This will then be added to the page when it is rendered and can be executed by the jQuery on document.ready(); or any other function / event.

    Example code :

        string FunctionStr = "";
    
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Some JS Function", FunctionStr);
    

    The answers from Anand and Daniel may better suit your desired approach but this is a 3rd option if you desire one.

提交回复
热议问题