user968441
user968441

Reputation: 1471

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.

Upvotes: 1

Views: 7487

Answers (1)

Kevin Main
Kevin Main

Reputation: 2344

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%>";

Upvotes: 3

Related Questions