ASP.NET.in.a.Nutshell.Second.Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

ASP.NET.in.a.Nutshell.Second.Edition [Electronic resources] - نسخه متنی

G. andrew Duthie; matthew Macdonald

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








13.3 Collections Reference


AllKeys

Dim StateVars(Application.Count) As String
StateVars = Application.AllKeys

Returns a
string array of key names stored in the HttpApplicationState object.

Parameter


StateVars



A variable of type String array that will receive the array of key
names.



Example


The example displays all keys of data stored to the Application
object:

Sub Page_Load( )
Dim I as Integer
Dim StateVars(Application.Count - 1) As String
StateVars = Application.AllKeys
For I = 0 to StateVars.Length - 1
Message.Text = Message.Text + StateVars(I) + "<br/>"
Next I
End Sub

Notes


This property provides a list of key names assigned to all current
Application variables.

Contents

HttpApplicationState = Application.Contents

Returns a reference to the current
HttpApplicationState instance.

Parameter


HttpApplicationState



A variable of type HttpApplicaitonState that will receive the
Contents reference.



Example


The example below calls the RemoveAll method through the Contents
collection reference and then writes a message:

Sub Page_Load( )
Application.Contents.RemoveAll( )
Message.Text = "Removed all items from current Application."
End Sub

Notes


This property is provided for backward compatibility with classic
ASP. Properties such as the Item property and methods such as Remove
and RemoveAll were accessed via the Contents property in classic ASP.
In new ASP.NET development, you should access these members directly.
For example, instead of calling the RemoveAll method through the
Contents property, you can call RemoveAll method directly:

Application.RemoveAll( )

Keys

KeysCollection = Application.Keys

Returns a
NameObjectCollectionBase.KeysCollection containing the string keys
associated with all values stored in the Application collection.

Parameter


KeysCollection



A variable of type NameObjectCollectionBase.KeysCollection that will
receive the Keys property value.



Example


The example loops through the collection of keys in the Application
collection, and then displays the key name and the value associated
with it by using the Text property of the Message control:

Sub Page_Load( )
Dim Key As String
Message.Text = "Application Keys:"
For Each Key in Application.Keys
Message.Text &= "<br/>Key:&nbsp;&nbsp;&nbsp;" & Key
Message.Text &= "<br/>Value:&nbsp;&nbsp;&nbsp;" & Application(Key)
Next
End Sub

Notes


The Keys property provides one of many ways to iterate over the
contents of the Application collection.

StaticObjects

HttpStaticObjectsCollection = Application.StaticObjects

Returns an HttpStaticObjectsCollection containing all objects
instantiated in

global.asax using the
<object runat="server">
syntax whose scope attribute is set to
Application.

Parameter


HttpStaticObjectsCollection



A variable of type HttpStaticObjectsCollection that will receive the
StaticObjects property value.



Example


The example uses the Count property of the
HttpStaticObjectsCollection class to display the
number of objects in the current application declared with the
<object scope="Application"
runat="server"/> syntax in

global.asax . It then checks the type of each
object, and if it is a Web TextBox control, adds it to the Controls
collection of the current page.

Sub Page_Load( )
Message.Text = "There are " & Application.StaticObjects.Count & _
" objects declared with the " & _
"&lt;object runat=&quot;server&quot;&gt; syntax " & _
"in Application scope."
Dim myobj As Object
For Each myObj in Application.StaticObjects
If myObj.Value.GetType.ToString( ) = _
"System.Web.UI.WebControls.TextBox" Then
Page.Controls.Add(myObj.Value)
End If
Next
End Sub

Notes


This property is provided for backward compatibility with classic
ASP. You should think carefully before instantiating objects with
Session or Application scope because of the impact such objects have
on resource usage and application scalability. In most cases, it is
advisable to limit objects to page scope.

Note that each object in the collection is represented by the
DictionaryEntry structure, so its key and value are not directly
accessible. To access the key and/or value, use the Key and/or Value
members of the DictionaryEntry structure.

/ 873