I am using a 3rd party control in a website project in VS 2010 that runs upon the 3.5 framework (yes, I need to upgrade it to 4.0 but I’m lazy). The 3rd party control has various client side events that can be handled using javascript. For example, it has an OnClientDoubleClick event:
<myUserCtrl:SpecialView ID="ucSpecialView" runat="server" OnClientDoubleClick="myDoubleClick">
</myUserCtrl:SpecialView>
and the accompanying javascript goes something like:
<script type="text/javascript" language="javascript">
function myDoubleClick(sender, args) {
// and we do whatever we need to in here
}
</script>
I am using masterpages and I have the javascript above located within the header content holder for the child page (basically I’m saying that I have the javascript in the right spot and I haven’t just plopped it down somewhere in the middle of my page).
My problem:
Using IE’s Developer Tools (found in the menu bar or by hitting F12), if I attempt to view the webpage with the Browser Mode set to “Internet Explorer 7” then I get a javascript error.
Microsoft JScript runtime error: ‘myDoubleClick’ is undefined
However, if I view the webpage by setting the Browser Mode to “Internet Explorer 8” then I do not see the javascript error and the control functions as it should (including the javascript function myDoubleClick).
Is this a problem with my 3rd party control (do I need to contact my vendor and bug them)? Or is it a problem with my code? I’ve done a decent amount of googling and scouring my code and I can’t seem to come up with anything.
EDIT:
It appears that another developer has included some javascript functions that run in the masterpage. Said functions are within a script tag that is itself within a div tag for reasons of which I’m not certain (although the div tag has runat attribute set to “server” and so I suspect its because the script tags are pulling some client id’s for one reason or another). In any case, this is highly unorthodox as the div tag surrounding the script tag is within the header tag (ie – div tags don’t belong in the header tag). This does appear to be the culprit. I did some testing and found that if I placed myDoubleClick function in the script tag that resides in the masterpage then the javascript error doesn’t occur on page load like it used to. However, this isn’t a viable solution since my javascript function also pulls upon various client id’s of controls of the child webpage and therefore must be located in the content place holder of the child webpage.
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript" language="javascript">
function myDoubleClick(sender, args) {
if (confirm("Are you sure you want to delete this node?")) {
$get("<%= btnDeleteNode.ClientID %>").click(); //full postback for delete node
}
}
</script>
</asp:Content>
The rendered HTML probably doesnt include arguments in the method call, so remove
sender, argsfrom your function.