StateBag クラスとは? わかりやすく解説

StateBag クラス

ページを含む、ASP.NET サーバー コントロールビューステート管理します。このクラス継承できません。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 StateBag
    Implements IStateManager, IDictionary, ICollection, IEnumerable
public sealed class StateBag : IStateManager,
 IDictionary, ICollection, 
    IEnumerable
public ref class StateBag sealed : IStateManager,
 IDictionary, ICollection, 
    IEnumerable
public final class StateBag implements IStateManager,
 IDictionary, 
    ICollection, IEnumerable
public final class StateBag implements IStateManager,
 IDictionary, 
    ICollection, IEnumerable
解説解説
使用例使用例

Text プロパティおよび FontSize プロパティを持つ複合 Label コントロールコード例次に示します。Control.Render メソッドコントロール呼び出されると、これらのプロパティビューステート保存されたり、ビューステートから取得されりします

' This control renders values stored in view state for Text and FontSize
 properties.

Imports System
Imports System.Web
Imports System.Web.UI

Namespace ViewStateControlSamples

    Public Class CustomLabel : Inherits
 Control
        Private Const defaultFontSize As
 Integer = 3

        ' Add property values to view state with set; 
        ' retrieve them from view state with get.
        Public Property [Text]() As
 String
            Get
                Dim o As Object
 = ViewState("Text")
                If (IsNothing(o)) Then
                    Return String.Empty
                Else
                    Return CStr(o)
                End If
            End Get
            Set(ByVal value As
 String)
                ViewState("Text") = value
            End Set
        End Property


        Public Property FontSize() As
 Integer
            Get
                Dim o As Object
 = ViewState("FontSize")
                If (IsNothing(o)) Then
                    Return defaultFontSize
                Else
                    Return CInt(ViewState("FontSize"))
                End If

            End Get
            Set(ByVal value As
 Integer)
                ViewState("FontSize") = value
            End Set
        End Property
        <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
        Protected Overrides Sub
 Render(ByVal Output As HtmlTextWriter)
            Output.Write("<font size=" & Me.FontSize
 & ">" & Me.Text &
 "</font>")
        End Sub

    End Class

End Namespace
// This control renders values stored in view state for Text and FontSize
 properties.
using System;
using System.Web;
using System.Web.UI;

namespace ViewStateControlSamples
{

    public class CustomLabel : Control
    {
        private const int
 defaultFontSize = 3;

        // Add property values to view state with set;
        // retrieve them from view state with get.
        public String Text
        {
            get 
            { 
                object o = ViewState["text"]; 
                return (o == null)? String.Empty
 : (string)o;
            }

            set
            {
                ViewState["Text"] = value;
            }
        }


        public int FontSize
        {
            get
            {
                object o = ViewState["FontSize"];
                return (o == null) ? defaultFontSize
 : (int)o;
            }
            set
            {
                ViewState["FontSize"] = value;
            }
        }

        [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name = "FullTrust")]
        protected override void Render(HtmlTextWriter
 output)
        {
            output.Write("<font size=" + this.FontSize.ToString()
 + ">" + this.Text + "</font>");
        }
    }
}
package ViewStateControlSamples;
// This control renders values stored in view state for Text and
// FontSize properties.
import System.*;
import System.Web.*;
import System.Web.UI.*;

public class Label extends Control
{
    // Add property values to view state with set;
    // retrieve them from view state with get.
    /** @property 
     */
    public String get_Text()
    {
        return ((String)(get_ViewState().get_Item("Text")));
    } //get_Text

    /** @property 
     */
    public void set_Text(String value)
    {
        get_ViewState().set_Item("Text", value);
    } //set_Text
    /** @property 
     */
    public int get_FontSize()
    {
        return (int)Convert.ToInt32(get_ViewState().get_Item("FontSize"));
    } //get_FontSize

    /** @property 
     */
    public void set_FontSize(int
 value)
    {
        get_ViewState().set_Item("FontSize", (Int32)value);
    } //set_FontSize

    protected void Render(HtmlTextWriter output)
    {
        output.Write("<font size=" + this.get_FontSize()
 + ">"
            + this.get_Text() + "</font>");
    } //Render
} //Label
継承階層継承階層
System.Object
  System.Web.UI.StateBag
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からStateBag クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からStateBag クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からStateBag クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「StateBag クラス」の関連用語

StateBag クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StateBag クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS