ControlDesigner.GetErrorDesignTimeHtml(Exception) 方法

定義

擷取可提供所指定例外狀況之相關資訊的 HTML 標記。

protected:
 virtual System::String ^ GetErrorDesignTimeHtml(Exception ^ e);
protected virtual string GetErrorDesignTimeHtml (Exception e);
abstract member GetErrorDesignTimeHtml : Exception -> string
override this.GetErrorDesignTimeHtml : Exception -> string
Protected Overridable Function GetErrorDesignTimeHtml (e As Exception) As String

參數

e
Exception

發生的例外狀況。

傳回

String

所指定例外狀況的設計階段 HTML 標記。

範例

下列程式碼範例示範如何在發生錯誤並呼叫 CreatePlaceHolderDesignTimeHtml 方法時產生控制項的設計階段 HTML 標籤。

// Generate the design-time markup for the control when an error occurs.
protected override string GetErrorDesignTimeHtml(Exception e) 
{
    // Write the error message text in red, bold.
    string errorRendering =
        "<span style=\"font-weight:bold; color:Red; \">" +
        e.Message + "</span>";

    return CreatePlaceHolderDesignTimeHtml(errorRendering);
} // GetErrorDesignTimeHtml
' Generate the design-time markup for the control when an error occurs.
Protected Overrides Function GetErrorDesignTimeHtml( _
    ByVal ex As Exception) As String

    ' Write the error message text in red, bold.
    Dim errorRendering As String = _
        "<span style=""font-weight:bold; color:Red; "">" & _
        ex.Message & "</span>"

    Return CreatePlaceHolderDesignTimeHtml(errorRendering)

End Function ' GetErrorDesignTimeHtml

備註

GetErrorDesignTimeHtml如果方法中 GetDesignTimeHtml 擲回例外狀況,通常會呼叫 方法。

給繼承者的注意事項

典型的設計模式是嘗試透過相關聯的控制項取得 HTML 標籤,然後如果遇到錯誤,請呼叫 GetErrorDesignTimeHtml(Exception) 方法。 如果控制項未傳回任何標記,請呼叫 GetEmptyDesignTimeHtml() 方法,如果未覆寫以提供特定標記,則會呼叫 CreatePlaceHolderDesignTimeHtml() 方法,其中應該包含控制項類型和識別碼的相關資訊。

適用於

另請參閱