Monday, February 14, 2011

Asp.Net Form Validation...YAY!!!

Form validation in ASP.Net is so much easier than you would think, using just two tags you can check if a text box is null...\/\/\/
 <table>  
    <tr align="right">  
       <td>Description of File: </td>  
       <td>  
         <asp:TextBox id="txtName" runat="server" />  
       </td>  
       <td align="left">  
         <asp:RequiredFieldValidator id="valTxtName" ControlToValidate="txtName" ErrorMessage="Please enter your Name!" runat="server" />  
       </td>  
     </tr>  
     <tr>  
       <td colspan="2" align="center""><asp:Button ID="add" runat="server"   
           Text="Add Old Pic" onclick="add_Click" /></td>  
     </tr>  
 </table>  
As long you use the the "asp" tags, using "asp:TextBox" and set the id property of the text box, this will come into play in the "asp:RequiredFieldValidator". The asp validator can be any place on the form, and can be used to send a message if the validation fails, by still having a null value.

No comments:

Post a Comment