2009-06-26 82 views
0

我想添加一個屬性到網頁控件。用於在ASP.NET控件中設置屬性的類型?

TextBox txt=new TextBox(); 
txt.Attributes["Foo"]="Bar" 

我需要把這個方法,但我的問題是,我不知道什麼樣的元素,我會被髮送給它 - 也許一個輸入也許選擇。本質上我需要下面的這個方法,但什麼是oControl?在VB中,我習慣稱它爲object

protected void SetAttrib(oControl){ 
    oControl.Attributes["Foo"]="Bar" 
} 

感謝

回答

6

我想你想要WebControl

protected void SetAttrib(WebControl oControl){ 
    oControl.Attributes["Foo"]="Bar" 
} 
2

的WebControl

+1

控制不具有財產屬性。 – tvanfosson 2009-06-26 18:07:23

+1

控件類沒有屬性屬性 – Kamarey 2009-06-26 18:09:49

0

做一個類型,你的所有器WebControls從繼承的參數。否則,你可以使它的類型對象和強制轉換。

0

使用WebControl類。

protected void SetAttrib(WebControl oControl, string bar) 
{ 
    oControl.Attributes["Foo"] = bar; 
}