My Account
Home Products Support Company Contact Buy

Disable ValidationSummary and JavaScript for a Page


There are a variety of reasons you might want to disable validation summary and client-side JavaScript for a page.
- Mahalakshmi Ramachandran, Software Engineer, Iron Speed, Inc.

April 19, 2006
Iron Speed Designer V3.2

Introduction

There are a variety of reasons you might want to disable ValidationSummary and client-side JavaScript for a page. In some situations, security concerns make it important to disable client-side JavaScript. In other situations, you might want to customize an error message to be more meaningful or explanatory.

Disabling ValidationSummary on a Page

The basic strategy is to handle your web page’s Init method and set the properties of the ValidationSummary control accordingly. Iron Speed Designer generates a ValidationSummary control on every page, usually named "ValidationSummary1". This control collectively represents the validation controls that have been defined for all fields in the page and is used to present a summary of the error messages from all these validators in a single location. The summary can be displayed as a list, as a bulleted list, or as a single paragraph based on the DisplayMode property of the ValidationSummary control. To prevent this error summary dialog from appearing, disable the control and make it invisible. The examples below show how to alter these and other properties of this control.

C#:

public class AddCategoriesPage : BaseAddCategoriesPage
{
    public AddCategoriesPage()
    {
        this.Init += new EventHandler(Page_Init);
    }
    // Occurs when the server control is initialized, which is the first step in the page’s lifecycle.
    private void Page_Init(object sender, System.EventArgs e)
    {
        // Select the type of display (list, bulleted list, or single paragraph) using the DisplayMode property.
        this.ValidationSummary1.DisplayMode = ValidationSummaryDisplayMode.BulletList;
        // The HeaderText property helps specify a message
        this.ValidationSummary1.HeaderText = "The following fields must have a value";
        // Hide the visibility of the control
        this.ValidationSummary1.Visible = false;
        // Disable the control
        this.ValidationSummary1.Enabled = false;
    }
} // End class AddCategoriesPage

Visual Basic .NET:

Private Sub MyPage_Init_DisableValidationSummary(ByVal sender As Object, ByVal e As System.EventArgs)
        Handles MyBase.Init
        ‘Select the type of display (list, bulleted list, or single paragraph) using the DisplayMode property.
        Me.ValidationSummary1.DisplayMode = ValidationSummaryDisplayMode.BulletList
        ‘ The HeaderText property helps specify a message
        Me.ValidationSummary1.HeaderText = "The following fields must have a value"
        ' Hide the visibility of the control
        Me.ValidationSummary1.Visible = False
        ' Disable the control
        Me.ValidationSummary1.Enabled = False
End Sub

Disabling JavaScript on a Page

Any BaseClasses control trying to register the client script will invoke the RegisterClientFocusScript and RegisterClientScript functions. In order to disable JavaScript for the page, override these methods and do not perform any operation within them. This ensures the JavaScript does not get registered (and hence not enabled) for the page.

C#:

protected override void RegisterClientFocusScript()
{
      // Do nothing
}
protected override void RegisterClientScript()
{
      // Do nothing
}

Visual Basic .NET:

Protected Overrides Sub RegisterClientFocusScript()
      'Do nothing
End Sub
 
Protected Overrides Sub RegisterClientScript()
      'Do nothing
End Sub

About the Author

Mahalakshmi Ramachandran
Software Engineer, Iron Speed, Inc.

Maha has experience developing Web Applications using the .NET technology and has been with Iron Speed since 2005.

Maha holds an M.S. degree in Computer Engineering from San Jose State University and a B.E. degree in Computer Science and Engineering from India.



  Privacy Statement