Reputation: 1300
I'm trying to put multiple user controls on the dashboard. But only one user control is visible.
Dashboard.aspx:
<table cellpadding="0" cellspacing="0" border="0" width="220px">
<tr>
<td>
<dc:MyControl ID="c1" runat="server"/>
</td>
<td>
<dc:MyControl ID="c2" runat="server"/>
</td>
</tr>
</table>
It looked like the global object created in user control overwrites the other one.
I then changed my javascript code as:
MyControl.ascx:
//Display gauge on the page (has some html5 elements like canvas)
<div id="gauge1" class="gauge"></div>
<script type="text/javascript">
var <%=this.ClientID%>global = new jGauge(); // Create a new gauge.
<%=this.ClientID%>global.id = 'gauge1'; // Link the new gauge to the placeholder DIV.
// This function is called by jQuery once the page has finished loading.
$(document).ready(function () {
<%=this.ClientID%>global.init(); // Put the gauge on the page by initializing it.
});
</script>
But still only one user control is visible. Any suggestions?
Upvotes: 0
Views: 171
Reputation: 102793
You still need to change the container ID (gauge1
) so that it's unique for each control, otherwise it will get overwritten. Something like this:
<div id="<%=this.ClientID%>gaugecontainer" class="gauge"></div>
And modify the Javascript to use the dynamic ID:
<%=this.ClientID%>global.id = '<%=this.ClientID%>gaugecontainer';
// Link the new gauge to the placeholder DIV.
Upvotes: 1
Reputation: 23811
try this
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="width:50%;">
<dc:MyControl ID="c1" runat="server"/>
</td>
<td style="width:50%;">
<dc:MyControl ID="c2" runat="server"/>
</td>
</tr>
Upvotes: 0