Share via


InitialValue Property

Sets or returns the base value for the validator. The default value is null.

public string InitialValue {
   get,
   set
}

Remarks

During validation, the validator compares a submitted value to the value of the InitialValue property. If the values are the same, the validator assumes that the value for the required field has not been filled in and reports a validation error.

Example

The following example demonstrates how to use the InitialValue property to compare the text of two Textbox controls. The RequiredFieldValidator control throws an error if the user name and password are identical.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
  If Not IsPostBack Then
      rfvUserName.Text = "User name and pwd can't be same"
  End If
      rfvUserName.InitialValue = txtUserPwd2.Text 

End Sub

<mobile:Form runat=server id="Form1" Alignment=center>
   <mobile:Textbox  runat="server" id="txtUserName"/>
   <mobile:RequiredFieldValidator runat="server" id="rfvUserName" 
      ControlToValidate="txtUserName" />
   <mobile:Textbox  runat="server" id="txtUserPwd2" password="true"/>
   <mobile:Command runat="server" id="Command1" text="Submit" />
</mobile:Form>

[C#]

void Page_Load(Object sender, EventArgs e)
{
   if(!IsPostBack)
   {
      rfvUserName.Text = "User name and pwd can't be same";
   }
   rfvUserName.InitialValue = txtUserPwd2.Text;
}
<mobile:Form runat=server id="Form1" Alignment=center>
   <mobile:Textbox  runat="server" id="txtUserName"/>
   <mobile:RequiredFieldValidator runat="server" id="rfvUserName" 
      ControlToValidate="txtUserName" />
   <mobile:Textbox  runat="server" id="txtUserPwd2" password="true"/>
   <mobile:Command runat="server" id="Command1" text="Submit" />
</mobile:Form>

See Also

RequiredFieldValidator Control

Applies to: RequiredFieldValidator Class