次の方法で共有


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 コントロールに Web ページでの共有ユーザーの可視性が設定されている場合は true。それ以外の場合は false。 既定値は false です。

属性

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

ブラウザーで 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 パーツパーソナル化の概要」を参照してください。

適用対象

こちらもご覧ください