设为首页 收藏本站
查看: 932|回复: 0

[经验分享] ASP.NET Outlook Style Toolbar Control

[复制链接]
累计签到:5 天
连续签到:1 天
发表于 2015-9-13 07:59:32 | 显示全部楼层 |阅读模式
By Ashish Kaila

An outlook style toolbar control in ASP.NET  




7 members have rated this article. Result:
http://www.codeproject.com/script/images/red.gif
http://www.codeproject.com/script/images/red.gif
http://www.codeproject.com/script/images/red.gif
http://www.codeproject.com/script/images/red.gifhttp://www.codeproject.com/script/images/white.gif
http://www.codeproject.com/script/images/white.gif

Popularity: 2.91. Rating: 3.44 out of 5.






  • Download source files - 9.15 Kb

  
Introduction

  This article describes how to develop sophisticated Outlook style toolbar as an ASP.NET server control. In the past, I have seen many similar controls, but either they weren't easy to use or didn't provide functionality I wanted. So I decided to give it a shot myself.
Features Of The Toolbar

  The toolbar simulates the Outlook style toolbar. A toolbar consists of various toolbar groups. Each toolbar group contains a header title and buttons following the header. Moreover, only one group can be active at any given time. Activation of groups can be performed by clicking on the titles that expands the group, contracting the previously active group.
  A button in the toolbar is characterized by a picture and a label. More generally, any button of the toolbar can be identified by the toolbar group and button index pair.
  This toolbar control lacks scrolling when the number of buttons in an active toolbar group exceeds the screen area, i.e.:
#Buttons in active group * Height of each button >
Toolbar Height - ToolbarGroupTitleHeight * Number of Total Groups.
  This is so because there is no runtime knowledge of web component dimensions. Perhaps, someone can guide me on this.
  Another thing to remember is that the toolbar drops down successfully only when container page is not designed in grid mode but in flow mode.
Code Construction

  When I set out to plan my server control, I had two major considerations. Firstly, the server control should be configurable at runtime. Secondly, it should be a child's play to modify element styles and hover / un-hover styles for elements. For one thing, I hate to have JavaScript dependency for my server controls (not easy to manage).
  The first requirement is fulfilled by the use of XML Schema and configuration file. The toolbar server control exposes ToolbarDefinitionFileName property that can be changed to reconfigure toolbar configuration. Alternatively, the same configuration file can be changed to reflect changes on next page refresh / postback. Toolbar control validates the XML contents of this file against its schema.

  Following is the schema of the toolbar:
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
<xs:schema id=&quot;Toolbar&quot; targetNamespace=&quot;http://tempuri.org/Toolbar.xsd&quot;
elementFormDefault=&quot;qualified&quot;
xmlns=&quot;http://tempuri.org/Toolbar.xsd&quot;
xmlns:mstns=&quot;http://tempuri.org/Toolbar.xsd&quot;
xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
<xs:complexType name=&quot;ToolbarButtonDef&quot;>
<xs:sequence>
<xs:element name=&quot;Caption&quot; type=&quot;xs:string&quot; nillable=&quot;false&quot; />
<xs:element name=&quot;ImagePath&quot; type=&quot;xs:string&quot; nillable=&quot;false&quot; />
<xs:element name=&quot;Alt&quot; type=&quot;xs:string&quot; />
</xs:sequence>
</xs:complexType>
<xs:complexType name=&quot;ToolbarGroupDef&quot;>
<xs:sequence>
<xs:element name=&quot;Caption&quot; type=&quot;xs:string&quot; nillable=&quot;false&quot; />
<xs:element name=&quot;ToolbarButton&quot; type=&quot;ToolbarButtonDef&quot; />
</xs:sequence>
</xs:complexType>
<xs:element name=&quot;Toolbar&quot;>
<xs:complexType>
<xs:sequence>
<xs:element name=&quot;ToolbarGroup&quot; type=&quot;ToolbarGroupDef&quot; />
<xs:element name=&quot;ScrollUpImagePath&quot; type=&quot;xs:string&quot;
default=&quot;images/scrollup.gif&quot; />
<xs:element name=&quot;ScrollDownImagePath&quot; type=&quot;xs:string&quot;
default=&quot;images/scrolldown.gif&quot; />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
  And following is a sample XML file that passes the validation check:
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
<Toolbar>
<ToolbarGroup Caption=&quot;WebService&quot;>
<ToolbarButton Caption=&quot;Upload File&quot; ImagePath=&quot;Images/4_47.gif&quot;
Alt=&quot;Upload Test File&quot; />
<ToolbarButton Caption=&quot;Download File&quot; ImagePath=&quot;Images/4_47.gif&quot;
Alt=&quot;Download Test File&quot; />
<ToolbarButton Caption=&quot;Update Line&quot; ImagePath=&quot;Images/schedule.gif&quot;
Alt=&quot;Update Line&quot; />
</ToolbarGroup>
<ToolbarGroup Caption=&quot;Group2&quot;>
<ToolbarButton Caption=&quot;Button3&quot;
ImagePath=&quot;Images/test.gif&quot; Alt=&quot;Test Button&quot; />
<ToolbarButton Caption=&quot;Button4&quot;
ImagePath=&quot;Images/test.gif&quot; Alt=&quot;Test Button&quot; />
</ToolbarGroup>
</Toolbar>
  Second requirement is fulfilled by the use of CSS style sheet file, and imposing CSS class name binding to various toolbar elements to provide runtime configurable styles / mouse hover events. For hovering the elements, switch state between <Element>Normal and <Element>Hover CSS classes, where Element denotes the element type.

Instantiating Toolbar

  Extract the toolbar project under wwwroot of IIS. For the purpose of using toolbar on the web form, include the CSS stylesheet as follows:

<LINK href=&quot;Shared/Styles/Toolbar.css&quot; type=&quot;text/css&quot; rel=&quot;Stylesheet&quot;>
  To start with, I would suggest to use the sample CSS provided in the downloads.
  Next, add reference of toolbar control from wwwroot\CustomWebControls folder to the web project, and drop the toolbar on the web form.

<customwebcontrols:toolbar id=&quot;Toolbar1&quot;
runat=&quot;server&quot;></customwebcontrols:toolbar>
  Next, create an XML config file for the toolbar and supply it to the toolbar control via Page_Load as follows:

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Toolbar1.ToolbarDefinitionFileName = &quot;~/Toolbar.xml&quot;;
}
Toolbar1.OnToolbarButtonClicked +=new
CustomWebControls.ToolbarButtonClicked(Toolbar1_OnToolbarButtonClicked);
}
  The above code attaches the XML contents (pasted as sample above) to the toolbar. The last part is to receive notifications from toolbar and handle them. This is done by handling ToolbarButtonClicked event (we already attach it in Page_Load event).

private void Toolbar1_OnToolbarButtonClicked(int Group, int Button)
{
// Toolbar Group
switch (Group)
{
case 0:
// Toolbar Button Within Group
switch (Button)
{
case 0:
// Do Something
break;
}
}
}
  For the purpose of convenience, Toolbar.css is included in the download to be used as CSS style sheet in your projects, and so is SampleToolbar.xml (sample configuration). That's it ! We are done... Any suggestions are welcome any time.

  Ashish Kaila



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112821-1-1.html 上篇帖子: Outlook与Hotmail的设置 下篇帖子: outlook的生日提醒为什么会在每次保存联系人后重复加入?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表