get property from code behind into aspx page

前端 未结 5 1344
野性不改
野性不改 2021-01-14 08:33

Is it possible to get the property(get; set; ) say Name from code behind(aspx.cs) file into jquery?

5条回答
  •  醉梦人生
    2021-01-14 08:38

    In the codebehind add the following:

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientVariable", "var clientVariable = '" + clientValue + "';", true);
    

    where clientValue is the value you would like to be accessible, by using the normal javascript variable clientVariable in your client code.

    Don't leave out the 'true' parameter at the end, as the default is to not add script tags, which prevents the script from working.

提交回复
热议问题