CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 8/14/2003 4:29:48 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 8 Views: 11 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
9 Items, 1 Pages 1 |< << Go >> >|
justin_dago
Asp.Net User
Validation Control based on presence of string value8/14/2003 4:29:48 PM

0/0

Greetings all,

I have to build a validation control that is similar to a requiredfield validator with a twist...

Background:
Got a DataGrid (for simplicity) with 3 columns, (x number of rows):
1. ProductID (bound straight text)
2. Vendor (template containing dropdown)
3. Model (template containing textbox)

Requirements:
If the ProductID is prefixed with the letters "TP" (eg TP-R-0554), the Vendor can not be a certain value (N/A) and the Model textbox cannot be blank.


How do I get the ProductID into my class to apply the logic? Can I apply this validator to both controls at once or simply use it twice?

This is my first custom control. So please be gentle. ;)

As always, thanks in advance,

--Justin
joteke
Asp.Net User
Re: Validation Control based on presence of string value8/16/2003 1:01:39 PM

0/0

Hmm,

I think it would be OK to create a CustomValidator as this is so specific scenario? For CustomValidator you wouldn't need to give specific ControlTovalidate property value if it doesn't suit the logic (but you can of course).

Take a look at this article first as it will give you the idea how ASP.NET Validation works.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspplusvalid.asp

Let's get back to the table after that. ;-)



Thanks,

Teemu Keiski
Finland, EU
justin_dago
Asp.Net User
Re: Validation Control based on presence of string value8/26/2003 3:00:58 PM

0/0

I've read the article twice, along with some research, and am ready to continue this dicussion.

It appears I have the following two choices (correct me if I am wrong):
1. use CustomValidator and build the logic into the OnServerValidate method setting args.IsValid as appropriate.
2. extend BaseValidator

The question still arises regarding accessing the Product ID, which decides whether or not the Page is valid.


Thanks,
Justin
justin_dago
Asp.Net User
Re: Validation Control based on presence of string value8/26/2003 3:37:17 PM

0/0

One more thing...

The actions are handled in a button click method...
is it possible to (or recommended) handle the validation here?

So, as I iterate through the DataGrid, if Product ID contains "TP" check for value "N/A" in Vendors dropdown and test for non-null Model TextBox. If vendor is "N/A" or Model is empty, set Page.IsValid to false. ??

Is this a viable solution?

-justin_dago
joteke
Asp.Net User
Re: Validation Control based on presence of string value9/2/2003 4:29:09 PM

0/0

With CustomValidator you can also put the validation on client if you are eager to. But at server-side it is easier (btw: good resource about client things generally : http://weblogs.asp.net/asmith/posts/25465.aspx)

Otherwise I think it should be OK except that you don't set Page.IsValid but rather event arguments's IsValid property in the method that handles the validation (OnServerValidate).




Thanks,

Teemu Keiski
Finland, EU
justin_dago
Asp.Net User
Re: Validation Control based on presence of string value9/2/2003 7:04:17 PM

0/0

Just to reiterate. Is it safe to say the following?
-Building a CustomValidator is the way to go.
-Implement the logic to determine whether or not the page is valid in the OnServerValidate event handler.


I still have a question about accessing values from other columns and controls within the DataGrid(or anywhere for that matter) to be used within my validator. This is the key, as these values are what will ultimately determine the validity of the Page.


I should be able to iterate through all DataGrid rows and columns, and based on the value of one column determine the value(s) of another.

so if ProductID starts with "TP"...Vendor(DropDownList) cannot be "N/A" and Model(TextBox) cannot be empty.


Now I'm even more confused. :)

Thanks for your patience.

--Justin

joteke
Asp.Net User
Re: Validation Control based on presence of string value9/2/2003 8:11:32 PM

0/0

You can loop through dataGrid's Items easily.


Dim dgi As DataGridItem
For Each dgi in DataGrid1.Items
....
Next


which is same as looping through its "rows". For every "row" you can search the controls using dgi.FindControl (in fact it doesn't matter in what column control exists as FindControl will find it) and then check the values and at the end determine the result of validation.
Thanks,

Teemu Keiski
Finland, EU
justin_dago
Asp.Net User
Re: Validation Control based on presence of string value9/3/2003 2:10:25 PM

0/0

Something like this:
protected void ServerValidation (object source, ServerValidateEventArgs args)

{
try
{
foreach(DataGridItem myDataGridItem in productsGrid.Items)
{
// Get Product Id and test whether it starts with "TP"
string productId = myDataGridItem.Cells[1].Text;

if(productId.StartsWith("TP"))
{
// Get Vendor DropDown Data
DropDownList listVendors =(DropDownList) dgItem.FindControl("ddlVendors");
string vendorName = listVendors.SelectedItem.Text;

// Get Model
TextBox txtModelBox = (TextBox) dgItem.FindControl("txtModel");

// Vendor cannot be "N/A" and Model cannot be empty
if(vendorName.Equals("N/A") || txtModelBox.Text == "" || txtModelBox.Text == null)
args.IsValid = false;
}
}
}
catch
{
args.IsValid = false;
}
}
will this work?

Thanks again,
Justin


P.S.
Just out of curiosity, how did you get your little code snippet to format? I've been on boards where you can do things like this:
[code]
// some code here
// nice and formatted (courier new 10pt)
[/code]
sort of a message board markup language
justin_dago
Asp.Net User
Re: Validation Control based on presence of string value9/3/2003 3:32:40 PM

0/0

Correction:
dgItem should be:
myDataGridItem
9 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
The CISA Prep Guide: Mastering the Certified Information Systems Auditor Exam Authors: John Kramer, Pages: 570, Published: 2003
Introducing Microsoft Office InfoPath 2003 Authors: Roger Jennings, Acey Bunch, Pages: 544, Published: 2004
Security for Microsoft Visual Basic .NET Authors: Ed Robinson, Michael Bond, Pages: 396, Published: 2003
IEEE International Conference on Multimedia Computing and Systems: Proceedings, June 7-11, 1999, Florence, Italy Authors: IEEE Computer Society, International Conference on Multimedia Computing, IEEE Circuit and Systems Society, IEEE Communications Society, IEEE Signal Processing Society, IEEE Circuits and Systems Society, IEEE Computer Society, IEEE Communications Society, Systems Society., Pages: 2, Published: 1999

Web:
Validation Control based on presence of string value - ASP.NET Forums Validation Control based on presence of string value. Last post 09-03-2003 11:34 AM by justin_dago. 8 replies. Sort Posts: ...
International Collegiate Programming Contest Validator Interface ... If there is no "answer file" to be input to the validator, the contest control system must pass an empty string ("") as the value of this parameter. ...
Base Validator Control Sample The base validator control described here implements the steps described in Developing a .... null) { return value.ToString(); } else { return string. ...
InformIT: Introduction to ASP.NET and Web Forms > Server Controls You access the string value of the control not through the Text property but ... If one of the standard validation controls does not do the job for you, ...
Zend Framework: Documentation The value of this metacommand varies based on whether you have multiple validators in ... By default, when you declare a filter or validator as a string , ...
AspAlliance.com: Alex Lowe's ASP.NET Tips and Tricks The add method expects two parameters - key (string) and value(string). ... Example 3: Using a confirmation box and validation controls on the same page ...
Blue Fish Development Group » Blog Archive » Validation in WDK The compare validator verifies that the input control value passes ... The inputmask attribute accepts a string of characters with the notations below. ...
DZone Snippets: Store, sort and share source code, with tag goodness Nicely, Sequel does supply you with Model.validations but its limited use since the actual validation values get crammed into a Proc. ...
slingshot: Validation cookbook The validator will also escape any text strings to reduce the likelihood of a ... Automatically set the initial value of the control to the current value of ...
Data Validation Controls in ASP.NET 2.0 Apr 11, 2008 ... If you do not specify an initial value, an empty string is assumed. ... Based on the results of the custom validation logic, you can set the ...




Search This Site:










application cache

how does .net framework 3.5 work?

windows principal - getting user groups

tracking invalid access attempts

genuinely free asp.net web hosting?

read text in a msword document

using code to enumerate all virtual directories in the current website

questions about this image gallery

inserting data from wizard into db

publish / approval stub

getting specs/info of all pc on a network

custom control

experience w/ vs.net 2008?

database questions on createuserwizard steps

retrieve assemblyattribute

windows authentication & network groups

module dev. using bitkraft

what's the skin you use?

global.asax and trying to define an application

store a text that has a bulleted list in database

a question on webparts in pagecategory. thanks

application blocks for .net

www.smcculloch.net - input string was not in a correct format.

copying files over a network - best way?

login page default redirect

part of the url missing

vs 2005 how to create a new web project in c#

difference between asp.net 2.0 inbuilt security and security application block?

how to run asp pages in visual studios?

dnn 3.1.1 - database question

 
All Times Are GMT