共用方式為


BaseValidatorDesigner.GetDesignTimeHtml 方法

定義

取得在設計階段用來呈現關聯控制項的標記。

public:
 override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String

傳回

字串,包含在設計階段用來呈現 BaseValidator 的標記。

範例

下列程式碼範例示範如何在設計階段覆寫 GetDesignTimeHtml 在相關聯控制項周圍繪製實心框線的方法,如果控制項的 BorderStyle 屬性值設定為 NotSetNone 欄位。

// Make the full extent of the control more visible in the designer.
// If the border style is None or NotSet, change the border to a 
// solid line. 
public override string GetDesignTimeHtml()
{
    // Get a reference to the control or a copy of the control.
    SimpleCompareValidator myCV = (SimpleCompareValidator)ViewControl;
    string markup = null;

    // Check if the border style should be changed.
    if (myCV.BorderStyle == BorderStyle.NotSet ||
        myCV.BorderStyle == BorderStyle.None)
    {
        // Save the current property setting.
        BorderStyle oldBorderStyle = myCV.BorderStyle;

        // Set the design-time property and catch any exceptions.
        try
        {
            myCV.BorderStyle = BorderStyle.Solid;

            // Call the base method to generate the markup.
            markup = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            markup = GetErrorDesignTimeHtml(ex);
        }
        finally
        {
            // Restore the property to its original setting.
            myCV.BorderStyle = oldBorderStyle;
        }
    }
    else
    {
        // Call the base method to generate the markup.
        markup = base.GetDesignTimeHtml();
    }

    return markup;
} // GetDesignTimeHtml
' Make the full extent of the control more visible in the designer.
' If the border style is None or NotSet, change the border to a 
' solid line. 
Public Overrides Function GetDesignTimeHtml() As String

    ' Get a reference to the control or a copy of the control.
    Dim myCV As SimpleCompareValidator = _
        CType(ViewControl, SimpleCompareValidator)
    Dim markup As String

    ' Check if the border style should be changed.
    If (myCV.BorderStyle = BorderStyle.NotSet Or _
        myCV.BorderStyle = BorderStyle.None) Then

        ' Save the current property setting.
        Dim oldBorderStyle As BorderStyle = myCV.BorderStyle

        ' Set the design-time property and catch any exceptions.
        Try
            myCV.BorderStyle = BorderStyle.Solid

            ' Call the base method to generate the markup.
            markup = MyBase.GetDesignTimeHtml()

        Catch ex As Exception
            markup = GetErrorDesignTimeHtml(ex)

        Finally
            ' Restore the property to its original setting.
            myCV.BorderStyle = oldBorderStyle
        End Try

    Else
        ' Call the base method to generate the markup.
        markup = MyBase.GetDesignTimeHtml()
    End If

    Return markup
End Function

備註

ErrorMessage如果衍生自 BaseValidator 類別之相關聯控制項的 或 Text 屬性是空字串 (「」) ,或 Display 屬性設定為 None 欄位, GetDesignTimeHtml 則方法會將 屬性設定 ErrorMessage 為控制項識別碼,該識別碼會以括弧 ([]) 括住,並將 屬性設定 DisplayStatic 欄位。 GetDesignTimeHtml接著會呼叫 GetDesignTimeHtml 基底方法來產生標記,並視需要將控制項屬性還原至其原始值。

適用於

另請參閱