0

I have set the session variable in backend(code behind ascx.cs page) where i want to access the same value in checkbox checked event in javascript ..

this is my code in javascript function

 $(document).ready(function () {
    $('#<%= gvPRCertInfo.ClientID %> input[type="checkbox"]').change(function () {

        var background1 = null;
        background1 = '<%= Session["FriendlyData"] %>';
        alert(background1); // i am getting this value 'system.data.dataset'
        if ($(this).is(':checked')) {
            var signValue = 
     $(this).closest('tr').children('td:eq(4)').html();

        }
    });
 });

This variable <%= Session["FriendlyData"] %> is a dataset and i have assigned some values in backend, now i want to access the same value in above js function

when i put alert I am getting value as System.data.dataset and i am not getting what is the value in session..

Could any one please help on how to get the dataset value in javascript function...

many thanks in advance

Glory Raj
  • 17,397
  • 27
  • 100
  • 203
  • see this post if it helps.. https://stackoverflow.com/questions/15519454/how-to-access-session-variables-and-set-them-in-javascript – Saurabh Solanki Nov 28 '17 at 04:01

1 Answers1

1

You need to stringify your codeback object in some way. For example,

//.aspx.cs
DataSet ds = GetMyDataSet();
Session["dataset"] = ds;

//.aspx
<script>
var ds = '<%=((DataSet)Session["dataset"]).GetXml()%>';
</script>
Alex Kudryashev
  • 9,120
  • 3
  • 27
  • 36