Proprietà InitialValue

Imposta o restituisce il valore di base per la convalida. Il valore predefinito è null.

public string InitialValue {
   get,
   set
}

Osservazioni

Durante la convalida viene eseguito un confronto tra un valore inviato e il valore della proprietà InitialValue. Se i valori sono uguali, la convalida presuppone che il valore del campo obbligatorio non sia stato immesso e segnala un errore di convalida.

Esempio

Nell'esempio che segue viene illustrato come utilizzare la proprietà InitialValue per confrontare il testo di due controlli Textbox. Il controllo RequiredFieldValidator genera un errore se il nome dell'utente e la password sono uguali.

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>

Vedere anche

Controllo RequiredFieldValidator

Si applica a: classe RequiredFieldValidator