2012-03-26 71 views
0

我正在使用錨點標記<a runat="server" id="myAnchor" rel="">並且我想從後面的代碼中設置rel值。我可以在後面的代碼中訪問anchore標記,但我沒有看到名爲rel的屬性。 任何機構都可以告訴我我必須做什麼。從後面的代碼設置錨點標記值

在此先感謝。

回答

4

您可以使用.Attributes屬性在控件上設置任何屬性。您沒有看到任何名爲rel的屬性,因爲您只需將runat =「server」放置在錨點上就可以使用一般的html控件bu,而不像包含更多特定屬性的HyperLink控件。

private void Page_Load() 
{ 
    //Example 1 
    myAnchor.Attributes.Add("rel", "relative"); 

    //Example 2 
    myAnchor.Attributes["rel"] = "relative"; 

} 

http://msdn.microsoft.com/en-us/library/7a9d6h4f.aspx

0

您可以使用 「屬性」,像這樣:

myAnchor.Attributes["rel"] = "...";