简体   繁体   中英

how to get property from code behind jquery variable?

I want to retrieve property value in jquery function and want to set it in variable. I am trying with below code but its not working.

.cs file

private string _Heading;
public string Heading { get { return _Heading; } set { _Heading = value; } }

.aspx

<script type="text/javascript">

    $(document).ready(function () {
      $("#btnShowSimple").click(function (e) {
        ShowDialog(false);
        e.preventDefault();
        var someProp = "<%= this._Heading; %>";
       alert(someProp);
      });
 </script>

What should i do to retrieve property value?? Anyone have solution than please help me in this.

Firstly, if the variable is private you will not be able to access it in your JavaScript so you should use the public Heading property instead.

Secondly, you have a semi colon in your JavaScript which needs to be removed so change this line

var someProp = "<%= this._Heading; %>";

To this

var someProp = "<%=this.Heading%>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM