Search code examples
javascriptc#.netextjsext.net

C# - Call the same javascript function inside a loop


Good day!

I am trying to achieve to change the color in the calendar cell of EXT Calendar for each holiday (holiday dates are from the database). But it only changes the first holiday which is the first line in the database.

My client side code :

        var applyCss = function (param1) {
        var css = "#CalendarPanel1-month-day-" + param1 + " {background-color: pink;}";

        Ext.net.ResourceMgr.registerCssClass("someCssClassId", css);
    };

My server side code:

DataTable holiday = Attendance.getInstance().getHolidays();

            for (var i = 0; i < holiday.Rows.Count; i++)
            {
                var hd = holiday.Rows[i]["holiday_date"].ToString();
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "applyCss(" + hd + ")", true);

            }

Appreciate any recommendations / suggestions / solutions. Thanks!


Solution

  • My suggestion would be instead of looping through the cells and RegisterClientScriptBlock function in server side you can get all the cells in one 'string array' and pass that to the client side function as a parameter via RegisterClientScriptBlock function.

    Your client side function's parameter should be of string array type and you can loop through the array in the client side which will fetch you the result.