0

I have some javascript to alter the functionality of a calendar extender control that I want to pass a parameter to (an ID) and the parameter never gets set. The function works when I hard code the parameter in the js file but I'm having trouble finding out why I can pass the parameter to the function.

Here is an example of the aspx code I'm using:

<ajax:CalendarExtender ID="clxStartMonth" runat="server" TargetControlID="txtStartMonth" Format="MM/yyyy" DefaultView="Months" ClientIDMode="Static" OnClientHidden="onCalendarHidden('clxStartMonth');" OnClientShown="onCalendarShown('clxStartMonth');"  ></ajax:CalendarExtender>

As you can see I'm trying to pass the control ID to the functions triggered by the OnClientHidden and OnClientShown events.

Here are the javascript functions:

function onCalendarHidden(clx) {
var cal = $find(clx);

if (cal._monthsBody) {
    for (var i = 0; i < cal._monthsBody.rows.length; i++) {
        var row = cal._monthsBody.rows[i];
        for (var j = 0; j < row.cells.length; j++) {
            Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", call);
        }
    }
}
}

function onCalendarShown(clx) {
var cal = $find(clx);
cal._switchMode("months", true);

if (cal._monthsBody) {
    for (var i = 0; i < cal._monthsBody.rows.length; i++) {
        var row = cal._monthsBody.rows[i];
        for (var j = 0; j < row.cells.length; j++) {
            Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", call);
        }
    }
}
}

function call(eventElement) {
var target = eventElement.target;
switch (target.mode) {
    case "month":
        var cal = $find("clxStartMonth");
        cal._visibleDate = target.date;
        cal.set_selectedDate(target.date);
        cal._blur.post(true);
        cal.raiseDateSelectionChanged();
        break;
}
}

Any ideas as to what I can do to fix this issue?

4
  • try logging the parameter inside the function to see if it is even defined. Can you show us where those parameters are being defined? Commented Jun 30, 2014 at 13:10
  • The function does receive the parameter but I then get a null reference error. It appears to not find the control if I call the function with a parameter even if I hard code the control ID instead of using the ID from the parameter. Commented Jun 30, 2014 at 13:48
  • Does the JavaScript reside in the same file as the ASPX? Or is there a separte .JS file for JavaScript? Commented Jun 30, 2014 at 15:34
  • It is in a separate file. Commented Jun 30, 2014 at 15:54

1 Answer 1

1

View your HTML source at runtime (right click the page and choose View Source). Verify that your control clxStartMonth is in fact your control's ID and it hasn't been altered to something else (example ctl0$clxStartMonth...). If the control ID has been altered, then set the ClientIDMode property on the clxStartMonth control to "Static".

Sign up to request clarification or add additional context in comments.

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.