This is a migrated thread and some comments may be shown as answers.

Why can't Javascript functions in User Control be referenced?

3 Answers 528 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 30 Dec 2010, 09:40 PM
I had previously posted this in the Slider section: http://www.telerik.com/community/forums/aspnet-ajax/slider/strange-msg-quot-microsoft-jscript-runtime-error-radslidingpane-beforeexpand-is-undefined-quot.aspx

But I now realize that this problem is not directly related to the Slider but likely has something to do with the loading sequence of Javascript.

To get to the heart of the problem, I created a simple little user control with this layout code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FullFaceMining.ascx.cs" Inherits="DataEntry.UserControls.FullFaceMining" %>

<script type="text/javascript">
  function radTreeView1_Test(sender, eventArgs) {
    debugger
  }
</script>

<telerik:RadTreeView ID="radTreeView1" runat="server" OnClientDoubleClick="radTreeView1_Test">
</telerik:RadTreeView>

Note that it doesn't actually "do" anything but it has the same pattern of a client-side event referring to a client-side event handler.  Lo and behold, it also fails when it's loaded.  So at least there's some consistency!

But please believe me ... this was all working fine for the past 6 months!!!  Suddenly and inexplicably, my project is seemingly unable to reference a user control's Javascript code now.  Clearly I've changed something that has effected this problem but what?!?

Robert W.
Vancouver, BC

3 Answers, 1 is accepted

Sort by
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 02 Jan 2011, 06:49 AM
Does the firebug console tab show ANY other javascript errors by any chance (on page load w/out clicking on anything?)

That's the only time I've found script functions not working...

Steve
0
Robert
Top achievements
Rank 1
answered on 02 Jan 2011, 07:53 AM
Steve,

I haven't seen any other Javascript errors.  The fact is, I can imagine that dynamically loading a User Control can get rather complicated.

I've actually solved the entire problem by moving all of the Javascript to external files.  To do this I had to dump all of the embedded ASP.Net control references.  Now everything is handled with jQuery finding the necessary objects.

It would be mighty useful is Telerik expanded their documentation and provided solutions that didn't involve embedded ASP.Net references for every solution.

Robert
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 02 Jan 2011, 04:26 PM
Well the only other thing I can think of is that the UserControl exists multiple times on the page, and in that case I could see there being problems since the same JS function would exist a whack of times....
Tags
General Discussions
Asked by
Robert
Top achievements
Rank 1
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Robert
Top achievements
Rank 1
Share this question
or