I'm not sure I worded the question the best way possible so I'll show my code example.
I have multiple pages that use the same javascript function. Instead of adding that function to every page, I added it to a .js and imported it in the site master. How can I add a handler to my objects that will call that function, the way I have it doesn't seem to be working.
Edit: I found the problem to be in
document.getElementById('<%= PostBackButton.ClientID %>').click();
The javascript function does get called correctly and the page does have a PostBackButton asp button, but the getelement is returning null.
//chart-ajaxDateSelection.js
function dateSelectionChanged(sender, args) {
selectedDate = sender.get_selectedDate();
document.getElementById('<%= PostBackButton.ClientID %>').click();
}
function getSlide()
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x=="slide")
{
return y;
}
}
}
My handler:
<asp:TextBox ID="OverviewChartStartDateTextBox" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="OverviewChartStartCal"
OnClientDateSelectionChanged="dateSelectionChanged" runat="server"
TargetControlID="OverviewChartStartDateTextBox">
</ajaxToolkit:CalendarExtender>
As you can see, I'm trying to call the dateSelectionChanged method when the selected date is changed on the ajax calendar.
dateSelectionChanged()inside a<script></script>on the master page itself, does your code work then?