0
我有下面的代碼,當我把這種類型的控件放在WebForm上時,它不會拋出異常正如你所期望的那樣,而不是<SELECT>很好地呈現。VB.NET - 繼承System.Web.UI.WebControls.DropDownList不調用「Render」方法
Imports System.ComponentModel
Imports System.Web.UI
<ToolboxData("<{0}:DropDownList runat=server></{0}:DropDownList>")> _
Public Class DropDownList
Inherits System.Web.UI.WebControls.DropDownList
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Throw New Exception("Hello World")
End Sub
End Class
不過,我有這樣的代碼,它工作得很好(在異常並拋出):
Imports System.ComponentModel
Imports System.Web.UI
<ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")> _
Public Class TextBox
Inherits System.Web.UI.WebControls.TextBox
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Throw New Exception("Hello World")
End Sub
End Class
任何想法,爲什麼?
您是否嘗試過重寫'CreateChildControls'呢? –
不幸的是我需要創建一個兄弟控件,所以我不能使用這個方法 – Jocie