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

1

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your support .. i have used hidden variable to get this done
@EnigmaState You can accept the answer if you find it useful.
Sorry i did not use your solution .. i made it one hidden variable and i assigned value in code behind, accessed it in javascript file
Code behind is the best solution. In such cases I use var a = '<asp:Literal runat="server" ID="ltrJsVal" />'; (and set .Text in codebehind). The question is did I answer the OP?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.