Tag: asp.net

  • Design Time Support in Custom Server Controls

    Visual Studio and ASP.Net provide excellent design time support for all controls. By Design Time support, I am referring to the Values and Description provided in the Properties window when a developer places his focus on the control.

    When designing custom server controls, providing such design time support is simple.

    [Category(“Custom”)]
    [Description(“Set the Corp Image URL.”)]
    public string CorpImageURL
    {
    get
    {
    return CorpImage.ImageUrl;
    }
    set
    {
    EnsureChildControls();
    CorpImage.ImageUrl = value;
    }
    }

    Here a property CorpImageURL to set the URL for a Image control is exposed. If the ‘get’ part of the Property is not defined, then the design-time support for the property will not be enabled. So to get the design time support, it is necessary to set the ‘get’ accessor.

    The attribute ‘Category’ is used to set the category in which the property will be displayed in the properties window. So in this case, a ‘Custom’ category is defined. If the Properties window is configured to show in the ‘Categorized’ mode, this new Category, ‘Custom’ will be displayed.

    The attribute ‘Description’ is used to set the description for the property. The description of the property to instruct what the developer is supposed to provide to the property.

    The attribute ‘DefaultValue’ is used to set the default value for the property. Note: This value will be displayed only on the properties window. It will not be assigned to the property by default.

  • ASP.Net Validation controls

    ASP.Net validation controls can be used to perform both client side validations. If the page containing a asp.net validation control is rendered in a page with Javascript disabled, the asp.net runtime creates code to automatically perform the validations in the server side.

    Server side validations can be invoked using the Page.Validate() method. The status of the validation is set to the Page.IsValid property by the asp.net runtime.


    protected void Page_Load(object sender, EventArgs e)
    {
    if (Page.IsPostBack)
    {
    Page.Validate();
    }
    }

    protected void button1_Click(object sender, EventArgs e)
    {
    if (!Page.IsValid) return;
    //Do something if validation passes.
    }

    This server side validation works on all major browsers. I have tested on IE, FireFox and Netscape.