ImageButton.CausesValidation Özellik

Tanım

Denetime tıklandığında ImageButton doğrulamanın gerçekleştirilip gerçekleştirilmeyeceğini belirten bir değer alır veya ayarlar.

public:
 property bool CausesValidation { bool get(); void set(bool value); };
public:
 virtual property bool CausesValidation { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(false)]
public bool CausesValidation { get; set; }
[System.Web.UI.Themeable(false)]
public virtual bool CausesValidation { get; set; }
[<System.ComponentModel.Bindable(false)>]
member this.CausesValidation : bool with get, set
[<System.Web.UI.Themeable(false)>]
member this.CausesValidation : bool with get, set
Public Property CausesValidation As Boolean
Public Overridable Property CausesValidation As Boolean

Özellik Değeri

Boolean

true denetim tıklatıldığında ImageButton doğrulama gerçekleştirilirse; aksi takdirde , false. true varsayılan değerdir.

Uygulamalar

Öznitelikler

Örnekler

Aşağıdaki örnekte, sayfa doğrulamasının gerçekleşmesini önlemek için özelliğinin CausesValidation nasıl kullanılacağı gösterilmektedir. Yönteminin Validate her doğrulama denetimini nasıl bağımsız olarak etkinleştiren bir yöntem olduğunu fark edin.

Not

Aşağıdaki kod örneği tek dosyalı kod modelini kullanır ve doğrudan arka planda kod dosyasına kopyalandığında düzgün çalışmayabilir. Bu kod örneği, .aspx uzantısına sahip boş bir metin dosyasına kopyalanmalıdır. Web Forms kod modeli hakkında daha fazla bilgi için bkz. Sayfa Kodu Modeli ASP.NET Web Forms.


<%@ 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> ImageButton CausesValidation Example </title>
<script runat="server">

      void SubmitButton_Click(Object sender, ImageClickEventArgs e)
      {
         
         // Determine which button was clicked.
         switch(((ImageButton)sender).ID)
         {

            case "CityQueryButton":

               // Validate only the controls used for the city query.
               CityReqValidator.Validate();

               // Take the appropriate action if the controls pass validation. 
               if (CityReqValidator.IsValid)
               {
                  Message.Text = "You have chosen to run a query for the following city: " + 
                     CityTextBox.Text;
               }

               break;

            case "StateQueryButton":

               // Validate only the controls used for the state query.
               StateReqValidator.Validate();

               // Take the appropriate action if the controls pass validation.
               if (StateReqValidator.IsValid)
               {
                  Message.Text = "You have chosen to run a query for the following state: " + 
                     StateTextBox.Text;
               }

               break;

            default:

               // If the button clicked isn't recognized, erase the message on the page.
               Message.Text = "";

               break;

         }
        
      }

   </script>

</head>

<body>

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

      <h3> ImageButton CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br />
               <asp:TextBox ID="CityTextBox" 
                    runat="server"/>
               <asp:RequiredFieldValidator ID="CityReqValidator"
                    ControlToValidate="CityTextBox"
                    ErrorMessage="<br />Please enter a city."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:ImageButton ID="CityQueryButton"
                    ImageUrl="SubmitImage.jpg"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br />
               <asp:TextBox ID="StateTextBox"  
                    runat="server"/>
               <asp:RequiredFieldValidator ID="StateReqValidator"
                    ControlToValidate="StateTextBox"
                    ErrorMessage="<br />Please enter a state."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:ImageButton ID="StateQueryButton"
                    ImageUrl="SubmitImage.jpg"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

      </table>

      <br /><br />

      <asp:Label ID="Message"
           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> ImageButton CausesValidation Example </title>
<script runat="server">

      Sub SubmitButton_Click(sender As Object, e As ImageClickEventArgs)
         
         ' Determine which button was clicked.
         Select Case (CType(sender, ImageButton)).ID

            Case "CityQueryButton"

               ' Validate only the controls used for the city query.
               CityReqValidator.Validate()

               ' Take the appropriate action if the controls pass validation. 
               If CityReqValidator.IsValid Then
           
                  Message.Text = "You have chosen to run a query for the following city: " & _ 
                     CityTextBox.Text
               
               End If

            Case "StateQueryButton"

               ' Validate only the controls used for the state query.
               StateReqValidator.Validate()

               ' Take the appropriate action if the controls pass validation.
               If StateReqValidator.IsValid Then
               
                  Message.Text = "You have chosen to run a query for the following state: " & _ 
                     StateTextBox.Text
               
               End If

            Case Else

               ' If the button clicked isn't recognized, erase the message on the page.
               Message.Text = ""

         End Select
        
      End Sub

   </script>

</head>

<body>

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

      <h3> ImageButton CausesValidation Example </h3>

      <table border="1" cellpadding="10">
         <tr>
            <td>
               <b>Enter city to query.</b> <br />
               <asp:TextBox ID="CityTextBox" 
                    runat="server"/>
               <asp:RequiredFieldValidator ID="CityReqValidator"
                    ControlToValidate="CityTextBox"
                    ErrorMessage="<br />Please enter a city."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:ImageButton ID="CityQueryButton"
                    ImageUrl="SubmitImage.jpg"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

         <tr>
            <td>
               <b>Enter state to query.</b> <br />
               <asp:TextBox ID="StateTextBox"  
                    runat="server"/>
               <asp:RequiredFieldValidator ID="StateReqValidator"
                    ControlToValidate="StateTextBox"
                    ErrorMessage="<br />Please enter a state."
                    Display="Dynamic"
                    EnableClientScript="False"
                    runat="server"/>
            </td>
            <td valign="bottom">
               <asp:ImageButton ID="StateQueryButton"
                    ImageUrl="SubmitImage.jpg"
                    CausesValidation="False"
                    OnClick="SubmitButton_Click"
                    runat="server"/>
            </td>
         </tr>

      </table>

      <br /><br />

      <asp:Label ID="Message"
           runat="Server"/>

   </form>

</body>
</html>

Açıklamalar

Varsayılan olarak, bir ImageButton denetim tıklatıldığında sayfa doğrulaması gerçekleştirilir. Sayfa doğrulama, sayfadaki bir doğrulama denetimiyle ilişkili giriş denetimlerinin tümünün doğrulama denetimi tarafından belirtilen doğrulama kurallarını geçip geçmeyeceğini belirler.

özelliği kullanılarak CausesValidation bir ImageButton denetim tıklatıldığında doğrulamanın hem istemcide hem de sunucuda gerçekleştirilip gerçekleştirilmeyeceğini belirtebilir veya belirleyebilirsiniz. Doğrulamanın gerçekleştirilmesini önlemek için özelliğini olarak falseayarlayınCausesValidation.

Bu özellik genellikle düğmeye false tıklandığında doğrulamanın gerçekleştirilmesini önlemek için Sıfırla veya Temizle düğmesi için olarak ayarlanır.

özelliğinin değeri olarak trueayarlandığında, denetimin CausesValidation ValidationGroup doğrulamaya neden olduğu ImageButton doğrulama grubunun adını belirtmek için özelliğini de kullanabilirsiniz.

Bu özellik temalar veya stil sayfası temaları tarafından ayarlanamaz. Daha fazla bilgi için bkzThemeableAttribute. temalar ve dış görünümler ASP.NET.

Şunlara uygulanır

Ayrıca bkz.