Condividi tramite


RequiredFieldValidator.InitialValue Proprietà

Definizione

Ottiene o imposta il valore iniziale del controllo di input associato.

public:
 property System::String ^ InitialValue { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string InitialValue { get; set; }
[System.Web.UI.Themeable(false)]
public string InitialValue { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.InitialValue : string with get, set
[<System.Web.UI.Themeable(false)>]
member this.InitialValue : string with get, set
Public Property InitialValue As String

Valore della proprietà

Stringa che specifica il valore iniziale del controllo di input associato. Il valore predefinito è Empty.

Attributi

Esempio

Nell'esempio seguente viene illustrato come utilizzare la InitialValue proprietà per assicurarsi che l'utente immetta un valore nella casella di testo.

Importante

In questo esempio è presente una casella di testo che accetta l'input dell'utente, che rappresenta una potenziale minaccia per la sicurezza. Per impostazione predefinita, ASP.NET pagine Web verificare che l'input dell'utente non includa elementi SCRIPT o HTML. Per altre informazioni, vedere Cenni preliminari sugli exploit di script.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RequiredFieldValidator InitialValue Example</title>
</head>
<body>
 
   <form id="form1" 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"/>
 
      <br />
         
      <asp:Button id="Button1"
           Text="Validate" 
           runat="server"/>
 
   </form>
 
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RequiredFieldValidator InitialValue Example</title>
</head>
<body>
 
   <form id="form1" 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"/>
 
      <br />
         
      <asp:Button id="Button1"
           Text="Validate" 
           runat="server"/>
 
   </form>
 
</body>
</html>

Nell'esempio seguente viene illustrato come utilizzare la InitialValue proprietà per assicurarsi che l'utente selezioni un elemento dalla casella di riepilogo.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RequiredFieldValidator InitialValue Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>RequiredFieldValidator InitialValue Example</h3>

      <asp:ListBox id="list"
           runat="server">
       
         <asp:ListItem Value="Australia">Australia</asp:ListItem>
         <asp:ListItem Selected="True" Value="NoCountry">--ChooseCountry--</asp:ListItem>
         <asp:ListItem Value="USA">USA</asp:ListItem>
       
      </asp:ListBox>
 
      <asp:RequiredFieldValidator id="valList"
           ForeColor="#FF0000"
           ErrorMessage="Selection Invalid!"
           ControlToValidate="list"
           InitialValue="NoCountry"
           EnableClientScript="False"
           runat="server"/>

      <br />

      <asp:Button id="Button1"
           Text="Submit"
           runat="server"/>

   </form>
 
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RequiredFieldValidator InitialValue Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>RequiredFieldValidator InitialValue Example</h3>

      <asp:ListBox id="list"
           runat="server">
       
         <asp:ListItem Value="Australia">Australia</asp:ListItem>
         <asp:ListItem Selected="True" Value="NoCountry">--ChooseCountry--</asp:ListItem>
         <asp:ListItem Value="USA">USA</asp:ListItem>
       
      </asp:ListBox>
 
      <asp:RequiredFieldValidator id="valList"
           ForeColor="#FF0000"
           ErrorMessage="Selection Invalid!"
           ControlToValidate="list"
           InitialValue="NoCountry"
           EnableClientScript="False"
           runat="server"/>

      <br />

      <asp:Button id="Button1"
           Text="Submit"
           runat="server"/>

   </form>
 
</body>
</html>

Commenti

Utilizzare questa proprietà per specificare il valore iniziale del controllo di input.

La convalida ha esito negativo solo se il valore del controllo di input associato corrisponde a questo InitialValue valore al momento della perdita dello stato attivo.

Annotazioni

Le stringhe nella InitialValue proprietà e nel controllo di input vengono tagliate per rimuovere spazi aggiuntivi prima e dopo l'esecuzione della stringa prima dell'esecuzione della convalida.

Questa proprietà non può essere impostata in base a temi o temi del foglio di stile. Per altre informazioni, vedere ThemeableAttribute e ASP.NET Temi e interfacce.

Si applica a