ASP.NET 选项卡服务器控件

分享于 

6分钟阅读

Web开发

  繁體

tabbar render example

介绍

我的很多客户在他们的web应用程序中请求标签导航。 我所处理的大多数应用程序都是业务类型应用程序,最喜欢的导航方案是使用一个"子"类别。 这样,我开发了一个控件,它可以提供一个标签栏可视化表示,可以配置为页面 aware,与内置 ASP.NET 角色API集成,支持 viewstate,可以通过编程方式操作,也可以用编程方式操作。

将标签栏添加到页面

首先,添加对 GeminiSoftworks.Web. Navigation.dll的引用。

接下来,将以下内容添加到 Web.Config 文件中,作为 <system.web>


<pages>


 <controls>


 <add tagPrefix="TabBar" 



             namespace="GeminiSoftworks.Web.Navigation" 



             assembly="GeminiSoftworks.Web.Navigation"/>


 <add tagPrefix="Tab" 



             namespace="GeminiSoftworks.Web.Navigation" 



             assembly="GeminiSoftworks.Web.Navigation"/>


 </controls>


</pages>



最后,将控件添加到页面。 可以通过将控件添加到studio工具箱,然后将控件拖到页面上,或者直接添加到 HTML:


<TabBar:TabBar ID="TabBar1" runat="server" Width="100%">


 <TabBar:Tab Link="~/default.aspx" Name="Home" PreserveFormOnTransfer="False" 



                Text="Home" ToolTip="Home" UseServerTransferMethod="False" 



                Visible="True" />


 <TabBar:Tab Link="" Name="Resources" PreserveFormOnTransfer="False" 



                Text="Resources" ToolTip="Resources" 



                UseServerTransferMethod="False" Visible="True" />


 <TabBar:Tab Link="" Name="Downloads" PreserveFormOnTransfer="False" 



                Text="Downloads" ToolTip="Downloads" 



                UseServerTransferMethod="False" Visible="True" />


</TabBar:TabBar>



现在,在浏览器中打开页面,你的页面应该像上面的示例图像一样呈现。

使用代码中的选项卡栏


protected void TabBar1_TabClick(object sender, 


 System.ComponentModel.CancelEventArgs ce)


{


 //basic tabbar operations...



 //example: get the tab that was clicked


 GeminiSoftworks.Web.Navigation.Tab t = 


 (GeminiSoftworks.Web.Navigation.Tab)sender;



 /* 


 * The following examples will modify the tabbar programmatically 


 * I will cancel the click event at the end of this function so that


 * the changes made will render


 * 


 * Typically, I will define constants for all the tab objects I need


 * and programmatically render the tabbar based on the circumstances.


 * The only case I declaritively set up tabs


 * is when they are basically static.


 * 


 * ** Remember **


 * If you are using the standard ASP.NET roles


 * configuration, secured tabs will be 


 * automatically suppressed for users that


 * don't have the appropriate authority to


 * use them. You can also create a derived


 * class and override the IsTabValidForRole


 * to implement custom security.


 * 


 * Roles = * (all users),? (authenticated users),


 * and any roles you define


 * 


 * ** Remember **


 * Tab authentication is based on the least secure role


 * (e.g. a tab with roles ("Admin","*") will render for all roles. 


 * 


 */



 //example: create a new tab


 GeminiSoftworks.Web.Navigation.Tab nt = 


 new GeminiSoftworks.Web.Navigation.Tab("NewTab", 


 "New Tab", "~/newpage.aspx", "New Tab");



 //example: set some pages that the tab should render 'active' for...


 nt.ActivePagesList = new string[] { "~/newsubpage1.aspx", 


 "~/newsubpage2.aspx" };



 //example: assign a role to view the tab


 //note: not assigning any roles means all users can view the tab, so


 //this example is the same as not setting the AllowRoles property


 nt.AllowRoles = new string[] { "*" };



 //example: add the new tab to the tabbar


 this.TabBar1.Tabs.Add(nt);



 //example: remove a tab by calling GetTab 


 //which accepts a tab name and returns a tab reference


 this.TabBar1.Tabs.Remove(this.TabBar1.Tabs.GetTab("Downloads"));



 /* cancel the click event to see the changes we made 上面 */



 //example: cancel the event


 ce.Cancel = true;


}



从源代码中可以学习到的东西

  • 设计器支持
  • 嵌入网络资源
  • Viewstate序列化
  • 使用HTML呈现而不是复合控件呈现
  • 辅助活动

还有什么需要做

在某些时候,我将向选项卡栏添加一些东西。 具体来说,它需要ADA支持,并且能够使用自定义图像代替文本进行标签。 有一天,我们将有几个小时免费完成这项工作,但是我决定提交这篇文章。 所以请欣赏。


Server  控制  asp  asp-net  tab  Tabbar  
相关文章