Depends on if you want to do this before postback or after postback.
The easy way is to do this after postback. To run a script right
after the form has been "Re-rendered" to the client, you need to
register a client startup script. If you only want this startup
script to run only when the server side OnSelectionChange event has
fired, you can use code similar to this:
protected void Calendar1_SelectionChanged(object sender,
EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(),
"Popup", "alert('After Post');", true);
}
If you want to run JavaScript before postback, then you have to
understand the calendar control better. The calendar control renders
to an html table where all the dates are html anchors. And each
anchors href contains JavaScript already. They all look similar to
this: <a href="javascript:__doPostBack('Calendar1','3219')"
The __doPostBack function is an ASP.NET mechanism to connect generic
postbacks with server side code attached to the event.
An easy way to inject your JavaScript into the href before the
postback is:
<script language=JavaScript>
var m = document.getElementById("Calendar1");
var n = m.getElementsByTagName("a");
for (i = 0; i < n.length; i++)
{
n.item(i).href = n.item(i).href.replace("__",
"alert('Before Post');__");
}
</script>
Here we get a "pointer" to the Calendar (html table) control, then we
get all the anchor tags and walk through each one, injecting our
JavaScript before the postback.
Hope this helps,
L. Lee Saunders
http://oldschooldotnet.blogspot.com