UserControl.IsPostBack 属性

定义

获取一个值,该值指示是正为响应客户端回发而加载用户控件,还是正第一次加载和访问用户控件。

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

属性值

如果是正为响应客户端回发而加载用户控件,则为 true;否则为 false

属性

示例

如果用户控件的 IsPostBack 属性返回 false,则以下示例将两个键值对添加到与用户控件关联的应用程序状态。 满足此条件时,代码通过用户控件的 Application 属性使用 Add 方法添加键及其值。

if (!myControl.IsPostBack)
{
  // Add new objects to the HttpApplicationState.
  // These will be maintained as long as the application is active.
  myControl.Application.Add("Author","Shafeeque");
  myControl.Application.Add("Date",new DateTime(2001,6,21));
  // Add an object to the cache with expirations 
  // set to 0.1 minute.
  myControl.Cache.Insert("MyData1", "somevalue", null, DateTime.Now.AddMinutes(0.1), Cache.NoSlidingExpiration);
}
If (Not myControl.IsPostBack) Then
  ' Add new objects to the HttpApplicationState.
  ' These will be maintained as long as the as the application is active.
  myControl.Application.Add("Author","Shafeeque")                
  myControl.Application.Add("Date",new DateTime(2001,6,21))
  ' Add an object to the cache with expirations
  ' set to 0.1 minute.
  myControl.Cache.Insert("MyData1", "somevalue", Nothing, DateTime.Now.AddMinutes(0.1), Cache.NoSlidingExpiration)        

适用于

另请参阅