0
我正在設計一個控件,我需要它從具有可包含服務器控件的文本屬性的類繼承。Webcontrol與文本屬性,可以容納服務器控件
下面就來說明一下我試圖解釋
<asp:myCustomControl id="myCustomControl1" runat="server" someProperty="something">
<asp:hyperlink id="myCustomControl1Hyperlink" runat="server" navigateUrl="someUrl">
Click here
</asp:hyperlink>
</asp:myCustomControl>
Protected Overrides Sub Render(_
ByVal writer As HtmlTextWriter)
If Not String.IsNullOrEmpty(Text) Then
writer.Write(_
"some html" + _
Text + _
"some other html"
)
End If
End Sub
這樣做的目的是,我可以決定如何呈現在我的控制的render
功能的控制,同時也展現了會是什麼一個例子在我的控制下成爲Text
財產。
我的第一次嘗試是從literal
繼承,因爲這會讓我在裏面寫<a>
標籤沒有任何問題。但是,最近我不得不通過<asp:hyperlink>
標籤更改<a>
標籤,並且這會引起'{0}' does not allow child controls.
例外。
所以我試着改變它,所以它從panel
繼承,但是這次在我的渲染函數中,我不能使用Text
屬性,既不是Me.Text,因爲它們都不存在。
'Control'沒有一個'Text'財產無論是。 – Shadowxvii
您在子控件中添加此屬性,然後構建 –