| | |
Conditional validation
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 452
Reputation:
Solved Threads: 82
1
#2 Oct 22nd, 2009
Try this code.
.aspx code
C# code
.aspx code
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoPage32.aspx.cs" Inherits="DemoPage32" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> Quantity : <asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox><br /> Date : <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> <asp:CustomValidator ID="cvValidateDate" runat="server" ErrorMessage="Date must be entered"></asp:CustomValidator><br /> <asp:Button ID="btnValidate" runat="server" Text="Validate" onclick="btnValidate_Click" /> </div> </form> </body> </html>
C# code
ASP.NET Syntax (Toggle Plain Text)
protected void btnValidate_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtQuantity.Text)) { int qty = int.Parse(txtQuantity.Text); if (qty > 0) { if (String.IsNullOrEmpty(txtDate.Text)) { cvValidateDate.ErrorMessage = "Date must be entered"; cvValidateDate.IsValid = false; } } } }
•
•
Join Date: Oct 2007
Posts: 13
Reputation:
Solved Threads: 0
0
#3 Oct 22nd, 2009
Thanks Ramesh S, this is great. Exactly what I was looking for.
Just in case anyone is interested , here is the same script in VB:
Just in case anyone is interested , here is the same script in VB:
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btnValidate_Click(ByVal sender As Object, ByVal e As EventArgs) If Not [String].IsNullOrEmpty(txtQuantity.Text) Then Dim qty As Integer = Integer.Parse(txtQuantity.Text) If qty > 0 Then If [String].IsNullOrEmpty(txtDate.Text) Then cvValidateDate.ErrorMessage = "Date must be entered" cvValidateDate.IsValid = False End If End If End If End Sub
![]() |
Similar Threads
- JavaScript Validation on Textbox (ASP.NET)
- Validation of age? (PHP)
- W3C Validation (HTML and CSS)
- coldfusion form validation question (ColdFusion)
Other Threads in the ASP.NET Forum
- Previous Thread: ASP.Net deployment problem
- Next Thread: Example of Inserting and Retrieving data from xml file
Views: 759 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for asp.net, validation
2.0 2008 action advice ajax anathor asp asp.net beginner box businesslogiclayer buttons c# checkbox control countryselector courier dataaccesslayer database datagridview download dropdownlist dropdownmenu email expose feedback fileuploader flash folder form freelance gridview html iframe iis input javascript jquery listbox method mssql online oracle php presence project redirect refer relationaldatabases rotatepage search select sorting sql-server string studio textbox tracking treeview trouble validatedate validation validator vb.net verify video virtualdirectory vista visual visual-studio visualstudio webarchitecture webdevelopemnt webdevelopment webprogramming windows7 wizard xml xsl






