views:

883

answers:

2

I've a webpage which contains a TabContainer

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
...
....
<form id="form1" runat="server">
    <asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
    <cc1:TabContainer runat="server" ID="tbcTabContainer" OnClientActiveTabChanged="ChangeTab()"></cc1:TabContainer>
</form>

which calls a js function which at the moment does nothing.

<script  type="text/javascript">
function ChangeTab()
{
    alert('Sucesss');
}
</script>

In my page load in the code behind I create a couple of tab panels and add them to the container. Now, my problem is that when i change tab, the javascript alert box shows but once i close it i get the error

Microsoft JScript runtime error: Sys.InvalidOperationException: Handler must be a function.

+2  A: 

You need to remove the parens from the attribute...

Change

OnClientActiveTabChanged="ChangeTab()"

to

OnClientActiveTabChanged="ChangeTab"

Just for clarification when you add the parens it is a literal method call whereas without the parens it is a reference to the method, these assignments work like callbacks expecting a delegate (method reference). Instead it is getting method call and will execute upon original eval (because it is a call) and then fail when attempting to be invoked properly because it is mot an actual method reference.

Quintin Robinson
correct. Still left wondering why? its ok with normal js to have empty paranthesis when a function has no params
I made an edit to provide a little info as to why.
Quintin Robinson
+1  A: 

Generally, you need only supply the function name to be called, so "ChangeTab()" should actually be just "ChangeTab".

Also, the function should technically implement the proper signature, which would be similar to a server-side event handler: ChangeTab(sender, e)....

mtazva