Connecting Tech Pros Worldwide Forums | Help | Site Map

How to Synchronize 2 multiviews with menu control-Help needed

Newbie
 
Join Date: Mar 2009
Location: New Zealand
Posts: 10
#1: Apr 21 '09
Hi, I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005

In a asp.net page, I have two multiview controls each has 2 views & its corresponding 2 menu items named Metric & Imperial. Individually both works fine.

But when I click "Metric", the other "Metric" should also be switched on and vice-versa for Imperial. How to achieve that?

The catch here is, one of the multiview control is inside a show/hide div with proper postback adjusted visibility.

Below ASP.Net page elements shows the first multiview

Expand|Select|Wrap|Line Numbers
  1. <style type="text/css">
  2. .header{cursor: hand; cursor:pointer;}
  3. #MasterCartonSpecs{display:none;}
  4. .tabs{position:relative;top:1px;left:10px;}
  5. .tab{border:solid 1px #C1C1C1;background-color:#eeeeee;padding:1px 3px;}
  6. .selectedTab{background-color:white;border-bottom:solid 1px white;}
  7. .tabContents{border:solid 1px #C1C1C1;padding:1px;background-color:white;}
  8. </style></head>
  9. <body>
  10.     <form id="form1" runat="server"> 
  11.  
  12. <asp:Menu ID="TabMenu1" Orientation="Horizontal" StaticMenuItemStyle-CssClass="tab" StaticSelectedStyle-CssClass="selectedTab" CssClass="tabs" OnMenuItemClick="TabMenu1_MenuItemClick" runat="server">
  13.    <Items>
  14.       <asp:MenuItem Text="Metric" Value="0" Selected="true" />
  15.       <asp:MenuItem Text="Imperial" Value="1" />
  16.    </Items>
  17. </asp:Menu>
  18. <div class="tabContents">  
  19.    <asp:MultiView ID="ProductSpecsMultiview" runat="server" ActiveViewIndex="0">
  20.       <asp:View ID="TabMenu1_Tab1" runat="server">
  21.           TabMenu1_Tab1 content
  22.       </asp:View>
  23.       <asp:View ID="TabMenu1_Tab2" runat="server">
  24.           TabMenu1_Tab2 content
  25.       </asp:View>
  26.    </asp:MultiView>
  27. </div>
Below ASP.Net page elements shows the second multiview

Expand|Select|Wrap|Line Numbers
  1. <a href="http://forums.asp.net/AddPost.aspx?ForumID=130#" class="header" onclick='ToggleDisplay("MasterCartonSpecs")'>Show more...</a><br /><br />
  2. <div id="MasterCartonSpecs">
  3.    <h3>Master Carton Specification</h3>
  4.    <asp:Menu ID="TabMenu2" Orientation="Horizontal" StaticMenuItemStyle-CssClass="tab" StaticSelectedStyle-CssClass="selectedTab" CssClass="tabs" OnMenuItemClick="TabMenu2_MenuItemClick" runat="server">
  5.       <Items>
  6.          <asp:MenuItem Text="Metric" Value="0" Selected="true" />
  7.          <asp:MenuItem Text="Imperial" Value="1" />
  8.       </Items>
  9.    </asp:Menu>
  10.    <div class="tabContents">  
  11.       <asp:MultiView ID="ProductSpecsDetailsMultiview" runat="server" ActiveViewIndex="0">
  12.          <asp:View ID="TabMenu2_Tab1" runat="server">
  13.              TabMenu2_Tab1 content
  14.          </asp:View>
  15.          <asp:View ID="TabMenu2_Tab2" runat="server">
  16.              TabMenu2_Tab2 content
  17.          </asp:View>
  18.       </asp:MultiView>
  19.    </div>
  20. </div> 
  21.  
  22.  
  23.  
  24. <input type="hidden" id="hiddenElement1" name="hiddenElement1" runat="server" />
  25. </form>
  26. <script language="JavaScript">
  27. <!--
  28. function ToggleDisplay(id)
  29. {
  30.  document.getElementById('<%= hiddenElement1.ClientID %>').value = '';
  31.  
  32.  var elem = document.getElementById(id);
  33.  
  34.  if (elem)
  35.  {
  36.   if (elem.style.display != 'block')
  37.   {
  38.    elem.style.display = 'block';
  39.   }
  40.   else
  41.   {
  42.    elem.style.display = 'none';
  43.   }
  44.  
  45.   document.getElementById('<%= hiddenElement1.ClientID %>').value = id + '~' + elem.style.display;
  46.  }
  47. }
  48. function windowOnLoad()
  49. {
  50.  var hiddenValue = document.getElementById('<%= hiddenElement1.ClientID %>').value;
  51.  var hiddenValueArray = hiddenValue.split('~');
  52.  
  53.  if ( hiddenValueArray.length >= 2 )
  54.  {
  55.   var idValue = hiddenValueArray[0];
  56.   var styleDisplayValue = hiddenValueArray[1];
  57.  
  58.   document.getElementById(idValue).style.display = styleDisplayValue;
  59.  }
  60. }
  61. window.onload = windowOnLoad;
  62. // -->
  63. </script>
  64. </body>
Code behind:

Expand|Select|Wrap|Line Numbers
  1.     Protected Sub TabMenu1_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
  2.         Dim index As Integer = Int32.Parse(e.Item.Value)
  3.         ProductSpecsMultiview.ActiveViewIndex = index
  4.     End Sub
  5.     Protected Sub TabMenu2_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
  6.         Dim index As Integer = Int32.Parse(e.Item.Value)
  7.         ProductSpecsDetailsMultiview.ActiveViewIndex = index
  8.     End Sub

But when I click "Metric", the other "Metric" should also be switched on and vice-versa for Imperial. How to achieve that?

Reply

Tags
asp.net 2.0, multiview, sql server 2005, vb.net, visual studio 2005