CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 3/11/2005 4:49:59 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 5 Views: 65 Favorited: 0 Favorite
6 Items, 1 Pages 1 |< << Go >> >|
SteveC71
Asp.Net User
Custom validation control3/11/2005 4:49:59 PM

0/0

I am working on a form that has about 60 check boxes on the page. Each check box needs to be checked before the form can be submitted. After getting the form designed I ran into the problem that Microsoft's validation controls do not allow validation of a check box. I searched the net for hours looking for an example and located a project that validates a checkbox list but not a single check box and worse for me it was in C# and I mainly use VB.NET. I found a C# to VB.NET converter and then modifed the code to as follows:


Imports System
Imports System.Text
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace Validators
Public Class RequiredFieldValidatorForCheckBoxes
Inherits BaseValidator
Protected Overrides Function ControlPropertiesValid() As Boolean
'This allows us to enter checkbox control without getting an error.
Return True
End Function 'ControlPropertiesValid
Protected Overrides Function EvaluateIsValid() As Boolean
Return Me.EvaluateIsChecked()
End Function 'EvaluateIsValid
Protected Function EvaluateIsChecked() As Boolean
Dim _chk As CheckBox = CType(Me.FindControl(Me.ControlToValidate), CheckBox)
If _chk.Checked = True Then
Return True
Else
Return False
End If
End Function 'EvaluateIsChecked
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
If Me.EnableClientScript Then
Me.ClientScript()
End If
MyBase.OnPreRender(e)
End Sub 'OnPreRender
Protected Sub ClientScript()
Me.Attributes("evaluationfunction") = "cb_vefify"
Dim sb_Script As New StringBuilder
sb_Script.Append("<script language=""javascript"">")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("function cb_vefify(val) {")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("var val = document.all[document.all[""")
sb_Script.Append(Me.ID)
sb_Script.Append("""].controltovalidate];")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("var col = val.all;")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("if ( col != null ) {")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("for ( i = 0; i < col.length; i++ ) {")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("if (col.item(i).tagName == ""INPUT"") {")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("if ( col.item(i).checked ) {")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("return true;")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("}")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("}")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("}")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append(ControlChars.Cr)
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("return false;")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("}")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("}")
sb_Script.Append(ControlChars.Cr)
sb_Script.Append("</script>")
Me.Page.RegisterClientScriptBlock("RBLScript", sb_Script.ToString())
End Sub
End Class
End Namespace


The code compiles and I was able to build the DLL and import it into VS but no matter what I do the control ends up firing as not valid and displays the error message associated with it. I'm pretty much at a loss here as to what I have done wrong. Can some point out my mistake(s)?

Thanks
Stephen
plblum
Asp.Net User
Re: Custom validation control3/11/2005 10:01:51 PM

0/0

Since you only wrote client-side evaluation, you need to look at and debug the JavaScript output. You've shown us the serve side code generator. But what does it output? Visual Studio.net has a debugger which lets you set up breakpoints into the javascript that is output to your web form. Use it to debug this problem.

You *must* write validation on the server side too. Not because its required by ASP.NET but because you have to assume your client-side validation code will not run. Microsoft's validators only support validation on DHTML browsers like IE and IE/Mac. Even those browsers allow turning off javascript. Finally, hackers can exploit the exposed javascript to work around your defenses.

FYI: I rewrote validation for ASP.NET with Professional Validation And More. The original validation system has so many limitations (which you are hitting) that force you to write custom code. I've built a system based on what users have requested. It includes 22 validators that all support client-side validation on IE, IE/Mac, Netscape 7, Mozilla, FireFox, Opera 7 and Safari.
In your case, you will use my CountTrueConditionsValidator. It is designed to detect how many checkboxes are marked. In your case, you need to confirm one or more is marked. It generates the javascript and handles server side validation too.
I also have a checkbox validator. It includes a utility to quickly convert a page to my validators.
--- Peter Blum
Creator of Professional Validation And More Suite, Peter's Date Package, and Peter's Polling Package
www.PeterBlum.com
SteveC71
Asp.Net User
Re: Custom validation control3/11/2005 11:41:07 PM

0/0

Peter,

Thank you for the reply. Apparently I am not understanding what I trying to do with this control.


Protected Overrides Function EvaluateIsValid() As Boolean

Return Me.EvaluateIsChecked()

End Function 'EvaluateIsValid

Protected Function EvaluateIsChecked() As Boolean

Dim _chk As CheckBox = CType(Me.FindControl(Me.ControlToValidate), CheckBox)

If _chk.Checked = True Then

Return True

Else

Return False

End If

End Function 'EvaluateIsChecked


In the code above I believed I was doing the server-side validation. I'm not sure where to turn next at this point. I don't believe that writing the code to do what I want is beyond my comprehension. I have to believe that I can accomplish writing this control.

Can you suggest any sites or books that might lead me in the direction I need to head so that I can complete this control. I want to learn so any help you can provide would be greatly appreciated. My target audience will only be using IE.

Thanks,
Stephen
plblum
Asp.Net User
Re: Custom validation control3/12/2005 5:34:33 PM

0/0

The call to Page.RegisterClientScriptBlock is a dead giveaway that you are writing client-side code (as it a function called ClientScript).

The only good docs I've found on validation is in the .net documentation.

I'm not sure why you are not interested in solving this through a solid and well-liked replacement to Microsoft's validation framework that only costs $100. You could download it, set it up, and move on to the task of delivering your web site. The reason I keep pointing this out is that as an expert in ASP.NET validation, I know how primitive the tools you have now really are. In fact, I put together a list of all of the issues I've found here to educate users. Microsoft may write nice things but not every webcontrol is feature rich enough to address even common situations and you are proving it by spending a lot of time researching and writing code. Believe me, your situation is very common and that's why I built a validator for it.
--- Peter Blum
Creator of Professional Validation And More Suite, Peter's Date Package, and Peter's Polling Package
www.PeterBlum.com
SteveC71
Asp.Net User
Re: Custom validation control3/14/2005 12:57:10 PM

0/0

The reason for my interest in solving this problem is the same reason for my interest in programing to begin with. I want to learn. Second I am working on this project with $0 budget. I'm trying to make a part of my job easier. Third I want to figure this out now mainly because the only answer I have recieved is "HERE BUY THIS". I'm sure your controls are great and thanks for your insight on this issue. I'm off to the .NET documentation to start my research on how I am going to figure this one out. Until then I will just change my form to utilize a text box and make the person filling out the form type yes.

Thanks,

Stephen
SteveC71
Asp.Net User
Re: Custom validation control3/14/2005 1:30:06 PM

0/0

Just an FYI that when I removed the ClientSide script the control acted exactly as I expected. I have no need for client side script in my project as the volume of the submitted form will be fewer than 10 a day. Again thanks for your guidance on the documentation, a quick read of it got this working for me.

Thanks,

Stephen
6 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
Sams Teach Yourself C# Web Programming in 21 Days Authors: Phil Syme, Peter Aitken, Pages: 560, Published: 2001
Programming ASP.NET: Building Web Applications and Services with ASP.NET 2.0 Authors: Jesse Liberty, Dan Hurwitz, Pages: 930, Published: 2005
ASP.NET: Tips, Tutorials, and Code Authors: Scott Mitchell, Pages: 878, Published: 2002
Pro .NET 2.0 Windows Forms and Custom Controls in C#: From Professional to Expert Authors: Matthew MacDonald, Pages: 1037, Published: 2005
Pro ASP. Net 3. 5 Server Controls and AJAX Components Authors: Rob Cameron, Dale Michalk, Pages: 740, Published: 2008
Developing and Implementing Web Applications with Visual Basic .NET and Visual Studio .NET: Exam Cram 2, 70-305 Authors: Kirk Hausman, Mike Gunderloy, Ed Tittel, Pages: 624, Published: 2003
ASP.Net Web Developer's Guide: Web Developer's Guide Authors: Robert Patton, Mesabāha Āhamada, Mesbah Ahmed, Jonothon Ortiz, Pages: 736, Published: 2002
Programming Data-driven Web Applications with ASP.NET Authors: Don Wolthuis, Donny Mack, Doug Seven, Pages: 704, Published: 2002
Pro .NET 2.0 Windows Forms and Custom Controls in VB 2005 Authors: Matthew MacDonald, Pages: 1036, Published: 2006

Web:
ASP.NET.4GuysFromRolla.com: Using the CustomValidator Control This property specifies what form field the validation control is set to validate. Hence, our custom validation function has the simple task before it: ...
Validating with a Custom Function Attach the handler to the event by assigning the method name to the onServerValidate attribute of the custom validator control. At runtime, the method is ...
Building a Custom Validator Control - Part 1 Well, the DotNetJunkies are at it again. We are starting our next book on building custom .NET server controls. So to follow with this category I'll be ...
ASP.NET QuickStart Tutorials Performing Custom Validation. The CustomValidator server control calls a user- defined function to perform validations that the standard validators can't ...
.NET - Creating a Custom Validation Control in ASP.NET Step 3: Our next step would be to create the custom validation control. ... Step 4: To create our custom validation control, Right click the project > Add ...
4GuysFromRolla.com - User Tips: Creating a Validation Control for ... However, there is an article here on 4Guys that examines how to create custom CheckBox and CheckBoxList validation controls, although it's done as an ASP. ...
Building a Custom Validator Using VB.NET Steven shows you how to create a custom validator control that validates for two validation requirements while making it possible to change the message ...
Creating A Designer Enabled Custom Validator Control Pt. I: ASP ... This is a two-part article. The first part of this article will discuss how to create server-side validation for your custom control and the second part ...
CodeProject: Custom Validation Control for Zip,Phone and Email ... This article shows how to develop a custom validation control to validate zip, phone,email in one control.; Author: Vinay Yeluri; Section: ASP.
How to: Validate with a Custom Function for ASP.NET Server Controls NET validation controls do not suit your needs, you can define a custom server- side ... The source parameter is a reference to the custom validation control ...

Videos:
Validating ASP.NET CheckBox (and similar) controls. http://blog.dmbcllc.com There are controls in the .NET framework that can not be wired to the standard validation controls. The checkbox control is ...
Validation Controls The demonstration uses a Web Form to create a data entry form that validates input data using ASP.NET Validation Controls. You'll also see how to dis...
BTC's Instrumentation & Control Program Intro The Associate in Applied Science degree in Instrumentation & Control Technology prepares students for employment to maintain, repair and troubleshoot...
MODx 0.9.5 PHP Application Framework. Ajax CMS. SEO CMS MODx is an open source PHP Application Framework that helps you take control of your online content. It empowers developers and advanced users to giv...
Validation Video for the song "Validation" by Lee Cannon-Brown
Packaging Aids Contimed 666 continuous sealer Contimed D666 Tabletop Medical Band Sealer The Contimed D666 is a validatable table top band sealer for use in the medical industry. It is equipped...
Better Interfaces with CSS, JavaScript, and the DOM Today's modern, standards-compliant browsers provide designers with vastly improved capabilities for creating rich user interfaces. In this session, ...
SJSU work control Test video 00001 for the work control validation project that I am spearheading. The goal is to validate work being completed in a well defined enve...
artist r.sahota interactive fine art catalogue 1997-2008 download: http://www.lulu.com/content/1950365 web broadband: http://www.sahota.110mb.com web 56k: http://art.sahota.google...
Cheese Checkweigher http://www.vbssys.com How can your plant find a Checkweigher that can weigh, classify, transport, and reject off-weight packages in a high-speed pro...




Search This Site:










index out of range??

problem with date values

querying user profiles?

can i access the controls on previous page without using postbackurl or server.tranfer?

asp.net ajax and sql reportingservices 2005

want to get rendered page output (i.e., the html that is getting sent to the browser).

asp.net with embeded technology

storing images on the db -- good practice or not?

opening my asp .net 2.0 page by only typing its url

help a asp.net c# noob plz :)

how to delete solution from vs.net?

page_unload()?

view pdf file in new browser window

how does a http request "remember" the event that fired the http request?

please help if you can, converting string to object

debug sql procdure in asp.net 1.1

refresh the page

setting a pages title in code?

best location to put the database connection string?

html page inconsistent with microsoft asp.net 2.0 step by step

data update c# .net 2.0

passing data between forms

sqldependency="commandnotification" not working

testing software, bug tracking software and best practices

intellisense

asp.net 3.5 using sql servers 2008 filestreaming capabilities

exporting datagrid to excel using c# and asp

query dns server

newbie trying to set up constants

display something in a datagrid only if certain value....

  Privacy | Contact Us
All Times Are GMT