WebPart.IsShared 属性

定义

获取一个值,该值指示 WebPart 控件是否为共享控件,即对 Web 部件页的所有用户都可见。

public:
 property bool IsShared { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool IsShared { get; }
[<System.ComponentModel.Browsable(false)>]
member this.IsShared : bool
Public ReadOnly Property IsShared As Boolean

属性值

Boolean

如果 WebPart 控件在网页中具有共享的用户可见性,则为 true;否则为 false。 默认值是 false

属性

示例

下面的代码示例演示了对自定义Web 部件控件的属性的使用IsShared。 此示例假定使用在类概述的“示例”部分中WebPart创建的自定义控件TextDisplayWebPart

在浏览器中加载网页并单击“ 检查共享 ”按钮时,代码将检查 IsShared 控件上的 TextDisplayWebPart 属性,并且属性的值是 true,因为该控件在页面的声明性标记中引用为静态控件。

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.CS.Controls" 
             Assembly="TextDisplayWebPartCS"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

void  button1_Click(object sender, EventArgs e)
{
  if (textwebpart.IsShared)
    label1.Text = "Text WebPart control is shared.";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      title="Zone 1"
      PartChromeType="TitleAndBorder">
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
        <partstyle
          borderwidth="1px"   
          borderstyle="Solid"  
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" 
            />
        </zonetemplate>
    </asp:webpartzone>
    <asp:Button ID="button1" Runat="server" 
      OnClick="button1_Click" 
      Text="Check Sharing" 
      />
    <asp:Label ID="label1" Runat="server" />
  </form>
</body>
</html>
<%@ page language="VB" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls" 
  Assembly="TextDisplayWebPartVB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    If textwebpart.IsShared Then
      label1.Text = "Text WebPart control is shared."
    End If
  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      title="Zone 1"
      PartChromeType="TitleAndBorder">
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
        <partstyle
          borderwidth="1px"   
          borderstyle="Solid"  
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" 
            />
        </zonetemplate>
    </asp:webpartzone>
    <asp:Button ID="button1" Runat="server" 
      OnClick="button1_Click" 
      Text="Check Sharing" 
      />
    <asp:Label ID="label1" Runat="server" />
  </form>
</body>
</html>

注解

共享Web 部件控件对网页的所有用户可见。 共享控件的相反是按用户控制的控件,该控件特定于用户,并且仅对将该控件添加到页面的用户可见。

如果用户在共享个性化设置范围内查看页面时添加动态控件,则会共享该控件。 如果用户处于用户个性化设置范围时添加控件,该 IsShared 控件的属性值将为 false

有关共享控件和每个用户控件的详细信息,请参阅Web 部件个性化设置概述

适用于

另请参阅