次の方法で共有


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

プロパティ値

コントロールが Web ページでユーザーの可視性を共有している場合は a0/&。それ以外の場合は。 既定値は false です。

属性

次のコード例では、カスタム Web パーツ コントロールに IsShared プロパティを使用する方法を示します。 この例では、WebPart クラスの概要の「例」セクションで作成したカスタム コントロール (TextDisplayWebPart) を使用することを前提としています。

ブラウザーで Web ページを読み込み、[共有の確認] ボタンをクリックすると、TextDisplayWebPart コントロールのIsShared プロパティがチェックされ、プロパティの値が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 パーツ コントロールは、Web ページのすべてのユーザーに表示されます。 共有コントロールの反対は、ユーザー固有のコントロールであり、そのコントロールをページに追加したユーザーにのみ表示されます。

ユーザーが共有パーソナル化スコープでページを表示しているときに動的コントロールが追加された場合、コントロールは共有されます。 ユーザーがユーザーパーソナル化スコープ内にある間にコントロールが追加されると、そのコントロールの IsShared プロパティ値が falseされます。

共有コントロールとユーザーごとのコントロールの詳細については、「 Web パーツのパーソナル化の概要」を参照してください。

適用対象

こちらもご覧ください