Export (0) Print
Expand All

RequiredFieldValidator.InitialValue Property

Gets or sets the initial value of the associated input control.

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

[ThemeableAttribute(false)] 
public string InitialValue { get; set; }
/** @property */
public String get_InitialValue ()

/** @property */
public void set_InitialValue (String value)

public function get InitialValue () : String

public function set InitialValue (value : String)

Property Value

A string that specifies the initial value of the associated input control. The default is String.Empty.

Use this property to specify the initial value of the input control.

Validation fails only if the value of the associated input control matches this InitialValue upon losing focus.

NoteNote

The strings in both the InitialValue property and the input control are trimmed to remove extra spaces before and after the string before validation is performed.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

The following example demonstrates how to use the InitialValue property to ensure that the user enters a value in the text box.

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<body>
 
   <form runat="server">

      <h3>RequiredFieldValidator InitialValue Example</h3>
 
      Name: 
      <asp:TextBox id="Text1" 
           Text="Enter a value" 
           runat="server"/>
 
      <asp:RequiredFieldValidator id="RequiredFieldValidator1" 
           InitialValue="Enter a value" 
           ControlToValidate="Text1"
           ErrorMessage="Required field!"
           runat="server"/>
 
      <p>
         
      <asp:Button id="Button1"
           Text="Validate" 
           runat="server"/>
 
   </form>
 
</body>
</html>

The following example demonstrates how to use the InitialValue property to ensure that the user selects an item from the list box.

Classic RequiredFieldValidator.InitialValue Example#2

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft