2012-09-15 20 views
0

我试图在仪表板上放置多个用户控件。但只有一个用户控件可见。在表格中添加多个用户控件

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> 

它看起来像在用户控件创建的全局对象将覆盖另一个。

然后我改变了我的javascript代码:

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> 

但仍然只有一个用户控件可见。有什么建议么?

回答

1

你仍然需要改变容器ID(gauge1),所以它的每个控制独特的,否则会被覆盖。事情是这样的:

<div id="<%=this.ClientID%>gaugecontainer" class="gauge"></div> 

并修改JavaScript使用动态ID:

<%=this.ClientID%>global.id = '<%=this.ClientID%>gaugecontainer'; 
// Link the new gauge to the placeholder DIV. 
+0

感谢您的时间。那么我尝试过,但仍然没有成功。我只是不知道有什么缺失... – benjamin54

+0

@ benjamin54我不知道;在这一点上,我会检查Firebug的任何Javascript错误/跟踪代码。 – McGarnagle

0

试试这个

<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> 

相关问题