Click here to Skip to main content
12,998,759 members (70,500 online)
Rate this:
Please Sign up or sign in to vote.
Hello could anyone provide any example, which show functionality with multiple user controls and javascript? Because I try to find solution with google and in other forum but without success.

So my user control looks like this:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Bar.ascx.cs" Inherits="Portal.Web.Widgets.Bar" %>
        <script src=""></script>
    <script src="Widgets/Widget.js" type="text/javascript"></script>
<dx:ASPxDockPanel ID="BarPanel" ClientIDMode="Static"  runat="server" DragElement="Window" ShowHeader="false"
    ShowShadow="false" Border-BorderWidth="0" ClientInstanceName="dpBar" AllowedDockState="DockedOnly">
            <dx:PopupControlContentControl id="pcBar"  runat="server" SupportsDisabledAttribute="True">
                <div id="dockPanelContent" style="width: 100%; height: 100%">
                        <dx:WebChartControl ID="chartControl" ClientIDMode="Static"  runat="server" ClientInstanceName="chartControl"
                                                             önCustomCallback="chartControl_CustomCallback" ClientSideEvents-EndCallback="chartControl_EndCallback">
                        <dx:ASPxButton ID="checkButton"  runat="server" ClientIDMode="static" ClientInstanceName="checkButton">
    <ClientSideEvents AfterResizing="dockPanel_AfterResizing"/>

And Widget.js javascript code in external file like this:
var waiting = false;
var callback = false;
var newWidth;
var newHeight = 0;
function dockPanel_AfterResizing(s,e) {
    if (s.IsDocked()) {
        newWidth = dockPanelContent.clientWidth;
        newHeight = dockPanelContent.clientHeight;
    else {
        newWidth = dockPanelContent.clientWidth - 10;
        var height = dockPanelContent.parentNode.parentNode.clientHeight;
        var divContent = dockPanelContent.parentNode;
        newHeight = height - parseInt($(divContent).css("padding-top")) - parseInt($(divContent).css("padding-bottom")) - 10;
    if (!waiting) {
        waiting = true;
        dockPanel = s;
        setTimeout("TimeoutedCallback()", 1000);
function TimeoutedCallback() {
    chartControl.PerformCallback(newWidth + "|" + newHeight);
function chartControl_EndCallback(s, e) {
    waiting = false;

On my page i put multiple user control instances
                               <add src="~/Widgets/Bar.ascx" tagName="Bar" tagPrefix="widget" />
                               <add src="~/Widgets/Gantt.ascx" tagName="Gantt" tagPrefix="widget" />

<div id="UC1">
            <widget:Bar ID="BarWidget"  runat="server" OwnerZoneID="ASPxDockZone1" ClientInstanceName="bar" ClientIDMode="static" />
<div id="UC1"></div>
            <widget:Gantt ID="GanttWidget"  runat="server" OwnerZoneID="ASPxDockZone2" ClientInstanceName="gantt" ClientIDMode="static" />

and try to run functions but no vain. Each user control's overridden by last usercontrol.
Please could you help me. Thanks in advance.
Posted 4-Apr-13 0:00am
Updated 4-Apr-13 0:03am
sri senthil kumar 4-Apr-13 6:28am
one suggestion would be if your doing anything with html control/tags then load those scripts in the ascx itself and put tht control as runat="server" and use control.ClientId. In your case it will be, assuming "dockPanelContent" div should be added with runat server attribute and load that script in the ascx.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


It's because of ClientInstanceName in your case is static it is always the same for all your controls. In ClientInstanceName you defining the name of variable where client side JS API object will be stored. And because these names are equals for all your user contriols (and browser knows nothing about user controls, only final HTML and JS) you getting the last one after page initialization (client side) phase.
+ similar behaviour with ClientIDMode="Static"

So how to fix:
1. in this part - newWidth = dockPanelContent.clientWidth;
you referring to node directly by ID, obviously if you have several node on page with the same ID it can't work.
I would recommend to search within sender main control to identify element
for example:
var dockPanelContent = $('#dockPanelContent', e.GetMainElement()).get(0);

2. Create some prefix that should be different for every control on page. Use this prefix to dynamically modify client instances and static IDs within your user control.
Rewrite your script, in you case it can't be static (actually it can but it's a long story), it should be different (because you'll have different IDs and client instance names) for every instance of user control on page.

Description of similar problem:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100