TagPrefixInfo 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義包含標籤相關資訊的組態元素。
public ref class TagPrefixInfo sealed : System::Configuration::ConfigurationElement
public sealed class TagPrefixInfo : System.Configuration.ConfigurationElement
type TagPrefixInfo = class
inherit ConfigurationElement
Public NotInheritable Class TagPrefixInfo
Inherits ConfigurationElement
- 繼承
範例
此範例示範如何宣告性地指定多個區段屬性的值,這些屬性 controls 也可作為類別成員 TagPrefixInfo 存取。
<system.web>
<pages>
<controls>
<!-- Searches all linked assemblies for the namespace -->
<add tagPrefix="MyTags1" namespace=" MyNameSpace "/>
<!-- Uses a specified assembly -->
<add tagPrefix="MyTags2" namespace="MyNameSpace"
assembly="MyAssembly"/>
<!-- Uses the specified source for the user control -->
<add tagprefix="MyTags3" tagname="MyCtrl" src="MyControl.ascx"/>
</controls>
</pages>
</system.web>
以下程式碼範例展示了如何利用該 TagPrefixInfo 類別程式化修改標籤前綴設定。 此程式碼範例是本類別更大範例 PagesSection 的一部分。
// Get all current Controls in the collection.
for (int i = 0; i < pagesSection.Controls.Count; i++)
{
Console.WriteLine("Control {0}:", i);
Console.WriteLine(" TagPrefix = '{0}' ",
pagesSection.Controls[i].TagPrefix);
Console.WriteLine(" TagName = '{0}' ",
pagesSection.Controls[i].TagName);
Console.WriteLine(" Source = '{0}' ",
pagesSection.Controls[i].Source);
Console.WriteLine(" Namespace = '{0}' ",
pagesSection.Controls[i].Namespace);
Console.WriteLine(" Assembly = '{0}' ",
pagesSection.Controls[i].Assembly);
}
// Create a new TagPrefixInfo object.
System.Web.Configuration.TagPrefixInfo tagPrefixInfo =
new System.Web.Configuration.TagPrefixInfo("MyCtrl", "MyNameSpace", "MyAssembly", "MyControl", "MyControl.ascx");
// Execute the Add Method.
pagesSection.Controls.Add(tagPrefixInfo);
// Add a TagPrefixInfo object using a constructor.
pagesSection.Controls.Add(
new System.Web.Configuration.TagPrefixInfo(
"MyCtrl", "MyNameSpace", "MyAssembly", "MyControl",
"MyControl.ascx"));
' Get all current Controls in the collection.
Dim j As Int32
For j = 0 To pagesSection.Controls.Count - 1
Console.WriteLine("Control {0}:", j)
Console.WriteLine(" TagPrefix = '{0}' ", _
pagesSection.Controls(j).TagPrefix)
Console.WriteLine(" TagName = '{0}' ", _
pagesSection.Controls(j).TagName)
Console.WriteLine(" Source = '{0}' ", _
pagesSection.Controls(j).Source)
Console.WriteLine(" Namespace = '{0}' ", _
pagesSection.Controls(j).Namespace)
Console.WriteLine(" Assembly = '{0}' ", _
pagesSection.Controls(j).Assembly)
Next
' Create a new TagPrefixInfo object.
Dim tagPrefixInfo As System.Web.Configuration.TagPrefixInfo = _
New System.Web.Configuration.TagPrefixInfo("MyCtrl", "MyNameSpace", "MyAssembly", "MyControl", "MyControl.ascx")
' Execute the Add Method.
pagesSection.Controls.Add(tagPrefixInfo)
' Add a TagPrefixInfo object using a constructor.
pagesSection.Controls.Add( _
New System.Web.Configuration.TagPrefixInfo( _
"MyCtrl", "MyNameSpace", "MyAssembly", "MyControl", _
"MyControl.ascx"))
備註
這個 TagPrefixInfo 類別允許你以程式方式存取並修改儲存在設定檔中的標籤前綴資訊。 它提供與 ASP.NET @Register 指令相同的功能。 標籤前綴會將「命名空間」ASP.NET 關聯到必須包含的組件與命名空間,才能讓自訂控制項與使用者控制項正常運作。
TagPrefixInfo 物件會被儲存為物件的 TagPrefixCollection 成員。 這個 TagPrefixCollection 類別允許你程式化地存取並修改 controls 設定檔該 pages 區段的子節。
TagPrefixInfo 物件會透過元素 add 加入集合,並指定 tagPrefix 屬性值及其他相關屬性的值。 其他必要資訊會依你將使用指定標籤前綴的控制類型而有所不同:
相同的 tagPrefix 值可用來映射到多個組件或命名空間。
備註
當指定來源時,使用者控制項本身不得與頁面同一個目錄。 如果是,當你嘗試載入頁面時會跳出執行時錯誤。
建構函式
| 名稱 | Description |
|---|---|
| TagPrefixInfo(String, String, String, String, String) |
利用傳遞的值初始化該類別的新 TagPrefixInfo 實例。 |