BaseValidatorDesigner.GetDesignTimeHtml Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the markup that is used to render the associated control at design time.

Namespace:   System.Web.UI.Design.WebControls
Assembly:  System.Design (in System.Design.dll)

public override string GetDesignTimeHtml()

Return Value

Type: System.String

A string containing the markup used to render the BaseValidator at design time.

If the ErrorMessage or Text property of the associated control that is derived from the BaseValidator class is an empty string (""), or if the Display property is set to the None field, the GetDesignTimeHtml method sets the ErrorMessage property to the control ID, which is enclosed in brackets ([]) and sets the Display property to the Static field. The GetDesignTimeHtml then calls the GetDesignTimeHtml base method to generate the markup, and restores the control properties to their original values, if necessary.

The following code example shows how to override the GetDesignTimeHtml method that draws a solid border around the associated control at design time if the value of the BorderStyle property of the control is set to the NotSet or None field.

// 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

.NET Framework
Available since 1.1
Return to top
Show: