Validators not Validating

Would anyone know why the validations on the page below wouldn't work. I am going through a book and learning asp.net and for some reason when I put in the last subroutine to insert the record the validation checks on the controls on the form no longer work.



<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>The Dorknozzle.com Intranet Site</title>
<script runat="server" language="VB">
Dim objConn As New SQLConnection("Server=XXXXXXX; database=Dorknozzle; uid=XXXXXXX; Pwd=XXXXXXXX;")
Dim objCmd As SQLCommand
Dim objRdr As SQLDataReader 

Sub Page_Load()
 If Not IsPostBack Then
   objConn.Open()
  
 objCmd = New SQLCommand("Select * From HelpDeskCategories", objConn)
 objRdr = objCmd.ExecuteReader()
 ddlCategory.DataSource = objRdr
 ddlCategory.DataValueField = "CategoryID"
 ddlCategory.DataTextField = "Category"
 ddlCategory.DataBind() 
 objRdr.Close() 
 
 objCmd = New SQLCommand("Select * From HelpDeskSubjects", objConn)
 objRdr = objCmd.ExecuteReader()
 ddlSubject.DataSource = objRdr
 ddlSubject.DataValueField = "SubjectID"
 ddlSubject.DataTextField = "Subject"
 ddlSubject.DataBind() 
 objRdr.Close()  
 
 objConn.Close()
  End If
End Sub

Sub SubmitHelpDesk(s As Object, e As EventArgs)
    objCmd = New SQLCommand("INSERT INTO HelpDesk (EmployeeID, StationNumber, CategoryID, SubjectID, Description, StatusID)" & _
 "VALUES (@EmployeeID, @StationNumber, @CategoryID, @SubjectID, @Description, @StatusID)", objConn)
 objCmd.Parameters.Add("@EmployeeID", 5)
 objCmd.Parameters.Add("@StationNumber", txtStationNum.Text)
 objCmd.Parameters.Add("@CategoryID", ddlCategory.SelectedItem.Value)
 objCmd.Parameters.Add("@SubjectID", ddlSubject.SelectedItem.Value)
 objCmd.Parameters.Add("@Description", txtDescription.Text)
 objCmd.Parameters.Add("@StatusID", 1)
 objConn.Open()
 objCmd.ExecuteNonQuery()
 objConn.Close()
 Response.Redirect("helpdesk.aspx")
End Sub
</script>

<link href="styles.css" rel="stylesheet" />
</head>
<body>
<form runat="server">
<table width="100%" border="0" cellspacing="0" cellpadding="0" background="Images/header_bg.gif">
 <tr>
  <td><img src="Images/header_top.gif" width="450" height="142" alt="dorknozzle.com: the official dorknozzle company intranet" /></td>
 </tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
  <td width="157"><img src="Images/header_bottom.gif" width="157" height="37" alt="" /></td>
  <td></td>
 </tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="10">
 <tr>
  <td valign="top" width="160">
   <!-- HyperLink Controls for navigation -->
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="index.aspx" runat="server" Text="Home" /><br />
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="helpdesk.aspx" runat="server" Text="HelpDesk" /><br />
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="employeestore.aspx" runat="server" Text="Employee Store" /><br />
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="newsletterarchive.aspx" runat="server" Text="Newsletter Archive" /><br />
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="employeedirectory.aspx" runat="server" Text="Employee Directory" /><br />
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="addressbook.aspx" runat="server" Text="Address Book" /><br /><br />
   <img src="Images/book_closed.gif" width="16" height="16" alt="+" /><asp:HyperLink NavigateUrl="admintools.aspx" runat="server" Text="Admin Tools" />
   <!-- End HyperLink Controls -->
  </td>
  <td valign="top">
  <h1>Employee HelpDesk Request</h1>
   <p>Station Number:<br />
   <asp:TextBox id="txtStationNum" CssClass="textbox" runat="server" /><br />
    <asp:RequiredFieldValidator id="rfvStationNum" Display="Dynamic" ControlToValidate="txtStationNum" ErrorMessage="You must enter a station number!" runat="server" />
    <asp:CompareValidator id="cvStationNum" Display="Dynamic" ControlToValidate="txtStationNum" Operator="DataTypeCheck" Type="Integer" ErrorMessage="Station number must be a number!" runat="server" />
    <asp:RangeValidator id="rvStationNum" Display="Dynamic" ControlToValidate="txtStationNum" MinimumValue="1" MaximumValue="50" ErrorMessage="Number must be between 1 and 50" Type="Integer" runat="server" /></p>
   <p>Problem Category:<br />
    <asp:DropDownList id="ddlCategory" CssClass="dropdownmenu" runat="server" /></p>
     <p>Problem Subject:<br />
    <asp:DropDownList id="ddlSubject" CssClass="dropdownmenu" runat="server" /></p>
     <p>Problem Description:<br />
    <asp:TextBox id="txtDescription" CssClass="textbox" Columns="40" Rows="4" TextMode="MultiLine" runat="server" /><br />
     <asp:RequiredFieldValidator id="rfvDescription" Display="Dynamic" ControlToValidate="txtDescription" ErrorMessage="You must enter a description of the problem!" runat="server" /></p>
      <asp:Button id="btnSubmit" CssClass="button" Text="Submit Request" onClick="SubmitHelpDesk" runat="server" /></p>
    <asp:ValidationSummary id="vsSummary" ShowMessageBox="true" ShowSummary="false" runat="server" />
  </td>
 </tr>
</table>

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


Jim
0
JimAmigo
9/22/2005 4:45:12 PM
asp.net.web-forms 93655 articles. 3 followers. Follow

4 Replies
826 Views

Similar Articles

[PageSpeed] 11

Surround the code in your SubmitHelpdesks routine with:

If IsValid
.....
End If


It might be that the client side validation isn't working because the validator controls don't render client script for the specific browser (I've seen this happen on certain FireFox versions).

So checking the Page's IsValid property is always recommended practice.

Cheers,
Wim


Wim Hollebrandse
---
http://www.zealandit.com
0
WimH
9/23/2005 12:07:01 PM
read this 

http://forums.asp.net/1023164/ShowPost.aspx
Fadil Alnassar
www.fadilalnassar.com | FREE Nodil Tab Control
http://www.mefranchising.com
0
fadil1977
9/23/2005 12:30:19 PM
I changed the code as requested... and it is working as should now. Could you explain why it didn't work as explained in the book I am using for learning. Just hoping to learn more.

Thanks for all your help!
Jim
0
JimAmigo
9/28/2005 4:07:15 PM
I wrote an article on this and many other issues with validation: www.aspalliance.com/699.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
9/28/2005 9:25:13 PM
Reply:

Similar Artilces:

To validate or not to validate
Hey people! Here is my situation - I've created a dynamic data website with one table. The fields of this table are mostly varchar() not NULL, and all fields are defined with default value. When trying to insert new row with empty values I get required validation on all fields. What would be the best way to enable this validation only on some of these fields, while using default values for the others? For example empty string for varchar or 0 for int, etc Thanks Michael no in this case it will be add what error its return when u add. .Net DeveloperWeb Site Design and W...

Validator.Validate() ?
Hello guys,When I created a function to do custom validation I tried to use RegularExpressionValidator.Validate(). My code: 1 protected void EvaluateNewGateWay(object source, ServerValidateEventArgs args) 2 { 3 if (chBoxNewGW.Checked) 4 { 5 RegularExpressionValidator rev = new RegularExpressionValidator(); 6 rev.ErrorMessage = "REV Error"; 7 rev.ControlToValidate = "txtNewGW"; 8 rev.ValidationExpression = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"; 9 rev.Tex...

Web form and a gridview on the same page with data validators
I have a form where a user can submit a new customer and directly below that is a gridview where they can view the customer they just submited plus their other customers they have submited in the past. Now this gridview has the edit/update property so the user can modify their customer information. The whole idea is to have 1 single page where a user can do everything they need to without having to be linked to another page. On this page we can submit new customer info and view the status/info of existing customers and edit that info as needed. So far that works fine. I can submit the new c...

Page.Validate() not validating custom validators
Hi,when i call Page.Validate("myGroup") The custom validators in the validation group myGroup  are not validated, i.e.  validator.IsValid returns true even if the validator failed on  page submit. code snippet: Page.Validate("ToolsImplementation"); foreach (IValidator validator in this.Validators) { if (!validator.IsValid) { //take action on validation failure } }   the code works fine except if valida...

.net validation vs custom validation
Hello, Coming from a background of Classic ASP. I have a logic of validation which also does out security and account. Basically, we use a stored proceedure to validate and then also log success, failures, attempts etc Can this be done using .net validation or i have to build my own validation logic ? And how is this done ? thanks Ehi You can use Custom validator control Using the CustomValidator Control  Hosam Kamel Remember to click on Mark as answer on the post that helped you...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

web form validation
Hi, is it possible to use validation contorls with Javascript disabled in the client browser. If not, what are the alternatives? Many thanks Gareth Sure, it works fine. The only difference is that validation does not update when then change a field clientside... it does however update when the users pushes a submit button (after a round trip to the server)Pandora Tomorrow Yes, but you must make sure that you test that the page is valid before you do it, e.g. If page.Isvalid() Then ...... End IfIntelligence is a burden.Jagdip Singh AjimalManchester (and yes, I am a Manc...

About web Form validation?
Hi all, I have a textbox, and I want the data in it is decimal or integer. How can I build it with Web Form validator? Is there any way to build a textbox that only display numeric data? That means when you press the key is not '0...9', the textbox is not display. Thanks alot for support! The life is beautiful! you can use a regularexpressionvalidator and only allow numeric. ie: <asp:TextBox id="tb" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ControlToValidate="tb" ValidationExpression="^\d*" T...

web forms with validation
I have a web form that has several required fields, and then a sumit and clear button. What I'm having trouble with, is how to clear the form if all the required fields don't have content. Thanks Hi, did you set the CausesValidation property to False of the clear button? Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons. Thanks, figured it was something simple...

Web Form Validation
I am creating a dynamic form (from XML) and would like to use regular expression to validate. What is the best way to do this? -Tamim...

validating .net validation controls using javascript
 I need to validate multiple .net validation groups(a normal group would consist of RequiredFieldValidators, RegularExpressionValidators, ValidationSummary, etc) using javascript.  I am using Page_ClientValidate("GroupName") to validate the groups.  The problem arises when i validate multiple groups.  The validation summary and errors only appear for the last group validated or nothing appears if the last group validated returns true.  I want all validation summaries and errors to appear for all groups that return a false validation.  I'll never va...

Defaultbutton and Validators causing form to submit when it is not valid.
In Internet Explorer, when you have a single textbox, a defaultbutton on the form, and a validator, by pressing enter in the textbox the first time (if it is invalid), the validator fires and the form doesn't submit.  However, this sets __defaultFired to true, therefore the next time you click enter, even though the textbox is not valid, the page submits.  In this case, the page_load executes and ispostback is true, however the button onclick server side function does not fire. I have included an aspx page below that experiences this bug.  The bug can be witnessed by opening ...

Validating States dropdownlist with all other validation controls on form?
I have States dropdownlist  starts with "--" ListItem and 50 States. If user select "--" first ListItem, I need validate at client. Right now I am doing code behind side validation. But I have other controls on the form for validation, So I need to validate all at time. on submit button click.   Hi Srikanth, Place a required field for states dropdown list and set the "intial value" property of required field validator to "--". On Submit click validation is done. Above is the solution if i am not misunderstood you.   Regards, Pra...

Validation controls are triggereing other forms validation controls?
Can someone please look at this an explain whats going on. When you click on subscribe it triggers my registration form validation controls. I'not sure what "subscribe" is supposed to do, but if you dont want it to cause validation, set the CausesValidation property to false.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ Make sure the feild is an email address Hey coolkidsonly, your initial posting didn't show us anything to look at. We are just guessing here without the specifics. However, m...

Web resources about - Validators not Validating - asp.net.web-forms

CSE HTML Validator for Windows (Official Site) - Powerful HTML Validator, XHTML Validator, CSS Validator ...
CSE HTML Validator is a powerful and easy to use offline HTML, XHTML, CSS, JavaScript, and PHP syntax checker, HTML validator, XHTML validator, ...

DNSSEC/TLSA Validator
DNSSEC/TLSA Validator is a web browser add-on which allows you to check the existence and validity of DNS Security Extensions (DNSSEC) records ...

Feed Validator for Atom and RSS
F E E D Validator for Atom and RSS and KML Jump to navigation RSS Profile Support Added ( more ) Home · About · News · Docs · Terms Copyright ...

Credit Card Validator on the App Store on iTunes
Get Credit Card Validator on the App Store. See screenshots and ratings, and read customer reviews.

Not fare: new myki card validators lack account balance information
New myki card validators will not tell passengers what their fare is, nor their account balance, leaving unable to monitor their myki use as ...

Mozilla launches new JavaScript-based Add-ons Validator for developers
... that the validation tool provided by Mozilla is unreliable and difficult to use. Today the company announces that the old Python-based validator ...

Business Insider Built An Awesome Analytics Validator And You Can Use It
At a fast-growing media company like Business Insider, keeping accurate analytics is absolutely essential. Editors rely on our analytics dashboard ...

Jon Voight, Validator of Right-Wing Frenzy
Jon Voight was once known for his acting chops and, later, for fathering Angelina Jolie. These days? Well, he's known for his rabid right-wing ...

chocolatey/package-validator · GitHub
package-validator - Windows service to validate packages conform to pacakge standards

Bing Webmaster Tools Adds Markup Validator
The Bing Webmaster Blog announced they have added a new feature to the crawl section named Markup Validator. To access this new feature, login ...

Resources last updated: 2/8/2016 12:05:55 PM