2011-11-18 111 views
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 

任何想法,爲什麼?

+0

您是否嘗試過重寫'CreateChildControls'呢? –

+0

不幸的是我需要創建一個兄弟控件,所以我不能使用這個方法 – Jocie

回答

0

你確定你引用了新的類而不是標準的asp.net嗎?這是我能想到它沒有被調用的唯一原因。

您可能會檢查設計器文件是絕對肯定的。我有很多情況下,我在源視圖中更改控件類型,但設計器文件沒有更新,直到我去了設計視圖,並弄髒了東西。

+0

我檢查了設計器文件,並且他們引用了自定義控件 – Jocie