Google visualization is small inside AJAX Control Toolkit Tab Control

纵饮孤独 提交于 2019-12-02 08:51:42

Ok, I didn't get a single response to this post so here is how I worked around the problem, hope it helps someone.

I never actually got the the root of this problem but I found that if I delayed the loading of the Visualisations till the tab that contains it is clicked then the problem goes away.

In the TabControl I call a JavaScript function to load the tabs visualisation when clicked:

<cc1:TabContainer ID="TabContainer1" runat="server" OnClientActiveTabChanged="tabChanged">
  <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
    <ContentTemplate>
      <div id="visualization1" style="width: 300px; height: 300px;"></div>
    </ContentTemplate>
  </cc1:TabPanel>
    <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel2">
      <ContentTemplate>
        <div id="visualization2" style="width: 300px; height: 300px;"></div>
      </ContentTemplate>
  </cc1:TabPanel>
</cc1:TabContainer>

The JavaScript function

function tabChanged(sender, args) {
        var ActiveTab = sender.get_activeTabIndex();
        if (sender.get_activeTabIndex() == 0) {
            if (tab0Loaded != true) { 
                //load the visualisation
                new google.visualization.ColumnChart(document.getElementById('visualization2')).draw(data, null);
                tab0Loaded = true
            }
        }
        if (sender.get_activeTabIndex() == 1) {
            if (tab1Loaded != true) { 
                //load the visualisation
                new google.visualization.ColumnChart(document.getElementById('visualization2')).draw(data, null);
                tab1Loaded = true
            }
        }

 }

During postback the active tab could change, to cope with this I have a JavaScript function that executes when the page loads, if the current active tab is one containing a visualisation then I load it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!