web部件是ASP.NET WebForm里面的服务器控件,它涵盖的内容比较多,鉴于这种状况的话鄙人不打算深究下去了,只是局限于了解web.config配置里面的配置内容则可。 那么也得稍微说说啥是Web部件。引用MSDN的话:ASP.NET Web 部件是一组集成控件,用于创建 ...
web部件是get='_blank'>ASP.NET WebForm里面的服务器控件,它涵盖的内容比较多,鉴于这种状况的话鄙人不打算深究下去了,只是局限于了解web.config配置里面的配置内容则可。
那么也得稍微说说啥是Web部件。引用MSDN的话:ASP.NET Web 部件是一组集成控件,用于创建网站使最终用户可以直接从浏览器修改网页的内容、外观和行为。这些修改可以应用于网站上的所有用户或个别用户。还有引用它上面的插图
看了这个之后我就感觉就类似于QQ个人空间上的各个面板或者OA系统上的面板,可以按照每个用户的个人喜好去更改显示的内容,位置以及是否显示
更多关于Web部件的内容可参考本篇后面的参考的MSDN文章。关于Web部件的的WebPartManager和webParetZone就不说了,接下来则看看webParts配置节的内容
配置分两大块,personalization的是关于个性化设置数据的提供以及用户访问权限的;另一个是关于web部件连接的时候数据结构不一致需要转换的配置。
下面则先看看personalization的,这个例子是参考了MSDN。实现的效果大概是记录用户个性化数据,以及对数据的权限控制,本例子包含一个登录页面,一个示例页面,两个用户控件。
首先示例页面的内容如下
登录页面只是包含了一个登录控件
用于展现用户个性化设置的自定义控件 Color
<%@ Control Language="C#" %><script runat="server"> // User a field to reference the current WebPartManager. private WebPartManager _manager; // Defines personalized property for User scope. In this case, the property is // the background color of the text box. [Personalizable(PersonalizationScope.User)] public System.Drawing.Color UserColorChoice { get { return _coloruserTextBox.BackColor; } set { _coloruserTextBox.BackColor = value; } } // Defines personalized property for Shared scope. In this case, the property is // the background color of the text box. [Personalizable(PersonalizationScope.Shared) ] public System.Drawing.Color SharedColorChoice { get { return _colorsharedTextBox.BackColor; } set { _colorsharedTextBox.BackColor = value; } } void Page_Init(object sender, EventArgs e) { _manager = WebPartManager.GetCurrentWebPartManager(Page); } protected void Page_Load(object src, EventArgs e) { // If Web Parts manager scope is User, hide the button that changes shared control. if (_manager.Personalization.Scope == PersonalizationScope.User) { _sharedchangeButton.Visible = false; if (!_manager.Personalization.IsModifiable) _userchangeButton.Enabled = false; } else { _sharedchangeButton.Visible = true; if (!_manager.Personalization.IsModifiable) { _sharedchangeButton.Enabled = false; _userchangeButton.Enabled = false; } } } // Changes color of the User text box background when button clicked by authorized user. protected void _userButton_Click(object src, EventArgs e) { switch(_coloruserTextBox.BackColor.Name) { case "Red": _coloruserTextBox.BackColor = System.Drawing.Color.Yellow; break; case "Yellow": _coloruserTextBox.BackColor = System.Drawing.Color.Green; break; case "Green": _coloruserTextBox.BackColor = System.Drawing.Color.Red; break; } } // Changes color of the Shared text box background when button clicked by authorized user. protected void _sharedButton_Click(object src, EventArgs e) { switch (_colorsharedTextBox.BackColor.Name) { case "Red": _colorsharedTextBox.BackColor = System.Drawing.Color.Yellow; break; case "Yellow": _colorsharedTextBox.BackColor = System.Drawing.Color.Green; break; case "Green": _colorsharedTextBox.BackColor = System.Drawing.Color.Red; break; } } </script><html ="http://www.w3.org/1999/xhtml"><head> <title>WebParts Personalization Example</title></head><body><p> <asp:LoginName ID="LoginName1" runat="server" BorderWidth="500" BorderStyle="none" /> <asp:LoginStatus ID="LoginStatus1" LogoutAction="RedirectToLoginPage" runat="server" /></p> <asp:Label ID="ScopeLabel" Text="Scoped Properties:" runat="server" Width="289px"></asp:Label> <br /> <table style="width: 226px"> <tr> <td> <asp:TextBox ID="_coloruserTextBox" Font-Bold="True" Height="110px" runat="server" Text="User Property" BackColor="red" Width="110px" /> </td> <td> <asp:TextBox ID="_colorsharedTextBox" runat="server" Height="110px" Width="110px" Text="Shared Property" BackColor="red" Font-Bold="true" /> </td> </tr> <tr> <td> <asp:Button Text="Change User Color" ID="_userchangeButton" runat="server" OnClick="_userButton_Click" /> </td> <td > <asp:Button Text="Change Shared Color" ID="_sharedchangeButton" runat="server" OnClick="_sharedButton_Click" /> </td> </tr> </table></body></html>
原标题:webParts与Web部件
关键词:web
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。