Click here to Skip to main content
Rate this: bad
good
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="http://code.jquery.com/jquery-latest.js"></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">
        <ContentCollection>
            <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:WebChartControl>
                        <dx:ASPxButton ID="checkButton"  runat="server" ClientIDMode="static" ClientInstanceName="checkButton">
                        
                        </dx:ASPxButton>
                 </div>
            </dx:PopupControlContentControl>
        </ContentCollection>
    <ClientSideEvents AfterResizing="dockPanel_AfterResizing"/>
</dx:ASPxDockPanel>
 
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;
    }
    chartControl.SetWidth(newWidth);
    chartControl.SetHeight(newHeight);
 
    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
web.config
<controls>
                               <add src="~/Widgets/Bar.ascx" tagName="Bar" tagPrefix="widget" />
                               <add src="~/Widgets/Gantt.ascx" tagName="Gantt" tagPrefix="widget" />
default.aspx
<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" />
       </div>
       
 
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 1:00am
Edited 4-Apr-13 1:03am
v2
Comments
sri senthil kumar at 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
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
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: http://www.devexpress.com/Support/Center/p/B141088.aspx[^]
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2014
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