I'm working on an ASP.NET app
I'm using a UserControl for a year calendar. This UserControl has 12 asp.net calendar controls (for the 12 months of a year)
I'm trying to build a jscript function that can access to one (or more) of the 12 month calend开发者_高级运维ar, but I can't access them.
example:
"<asp:Calendar ID="CalendarJanuary" runat="server"></asp:Calendar>"
here's my function
function SetCalendar(controlId) {
document.getElementById(controlId+'_CalendarJanuary').VisibleDate = somedate
}
but this is allways throwing an error: 'Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object'
it seems is not finding the calendar and I'm sure i'm passing the right controlID
I don't think it's actually possible to access the server control properties from JavaScript. First of all, you can get a valid object by calling this line of JavaScript:
var control = document.getElementById("<%=CalendarJanuary.ClientID%>");
But this won't actually give you access to the ASP properties.
What you can do, is add a hidden input field to your form where you will store the new selection, which you set using JavaScript. Then on postback you could update your calendar with that value.
精彩评论