mardi 20 septembre 2016

How to get list of objects from session in javascript ASP.NET?

I have created checkboxes dynamically from list of checkboxes and i saved this list into a session and want to get this List of checkboxes from session in checkbox's onChange event. Here is the code.

    public static List <CheckBox> chklist = new List <CheckBox> ();
    void arrinit() {
        for (int i = 0; i < 31; i++) {
            //initializing list of checkboxes
            chklist.Add(new CheckBox());
        }
    }
    void show() {
        for (int i = 0; i < 30; i++) {
            TableCell cell4 = new TableCell();
            tRow.Cells.Add(cell4);
            ((IParserAccessor) cell4).AddParsedSubObject(chklist[i]);
            chklist[i].ID = "cbx_" + i.ToString();
            string a = "processChechBox('" + "ctl00_ContentPlaceHolder1_" + chklist[i].ID + "'); return false;";
            chklist[i].Attributes.Add("onChange", a);
            chklist[i].Attributes.Add("runat", "server");
        }
        Session["chk"] = chklist;
    }

    function processChechBox(id) {
        //here is the javascript function for checkbox onChange event
        debugger;
        var containerRef = document.getElementById(id);
        var data = document.getElementById(id);
        data.value = '1';
        data.checked = true;
        var a = '<%= Session["chk"]%>';
    }

var a = '<%= Session["chk"]%>'; this line is returning System.Collections.Generic.List1[System.CheckBox] instead of list processChechBox(id) this function is called on every check box checked.




Aucun commentaire:

Enregistrer un commentaire