Disable ValidationSummary and JavaScript for a Page
Updated June 5, 2006
Iron Speed Designer V4.0 and later
There are a variety of reasons you might want to disable validation summary 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.
The basic strategy is to handle your web page’s Init method and set the properties of the ValidationSummary control accordingly. Iron Speed Designer places 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 AddCategories : BaseAddCategoriesPage
{
public AddCategories()
{
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 AddCategories
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