0

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!

3 Answers 3

2

The reason is that you can only call Page.ClientScript.RegisterClientScriptBlock once per postback.

My suggestion: Create a string that will hold all the scripts you would like to run, and use that string in Page.ClientScript.RegisterClientScriptBlock:

DataTable holiday = Attendance.getInstance().getHolidays();
string script = string.Empty;

for (var i = 0; i < holiday.Rows.Count; i++)
{
     var hd = holiday.Rows[i]["holiday_date"].ToString();
     script += " applyCss(" + hd + "); ";
}
Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", script, true);
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Sir @Koby Douek first of all thank you for your response. Now I understand that I can only call one clientscript. However, your suggestion seems to not work. Regardless, thank you for helping me to understand! :)
1

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.

2 Comments

Thanks for the suggestion Sir! @Coder1991 Will give a feedback after i've tried
@Gen Sure. Hope you've understood my answer.
0

Use

X.AddScript("applyCss(" + hd + ")");

(but the array string appending approach provided by the others works too)

Comments

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.