473,804 Members | 3,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sharing a Validator

I have a form that contains a number of fields, all of which have
validators. There are two submit buttons, one to update a record and one to
add a record. Because the only difference in validation is to make sure
someone is not using a username that is already in use, I would like to be
able to use all the other validators for both the add and update buttons.
However, because as far as I know a validator can only be in one
validationgroup , that does not help me (although if they haven't already, I
think it would be a great improvement for the next version of the .NET
framework). Does anybody have any suggestions on a good way to solve my
problem (having 2 copies of each validator would work and be very simple,
but I would hope for a more efficient way)? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Nov 2 '07 #1
8 1341
Why not use only one button? Change the text of the button from "Add" to
"Update" depending on the data that is populating your form.

Use a hidden textbox to keep the ID of the item. So if the textbox has a ID
>0 then it's an update, else it's an Add.
It's a little more complex than that, but it might get you started.

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...
>I have a form that contains a number of fields, all of which have
validators. There are two submit buttons, one to update a record and one to
add a record. Because the only difference in validation is to make sure
someone is not using a username that is already in use, I would like to be
able to use all the other validators for both the add and update buttons.
However, because as far as I know a validator can only be in one
validationgrou p, that does not help me (although if they haven't already, I
think it would be a great improvement for the next version of the .NET
framework). Does anybody have any suggestions on a good way to solve my
problem (having 2 copies of each validator would work and be very simple,
but I would hope for a more efficient way)? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

Nov 5 '07 #2
I would do that, but unfortunately the client wants to always see both the
Add and Update buttons. If I were designing what the page should look like,
I would probably do something similar to your suggestion. But unfortunately,
an unhappy client means an unhappy boss which means an unhappy paycheck. I
guess that's all part of the business, with people caring so much about the
look of the page.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"ace_away" <ac*@away.comwr ote in message
news:uS******** ********@TK2MSF TNGP06.phx.gbl. ..
Why not use only one button? Change the text of the button from "Add" to
"Update" depending on the data that is populating your form.

Use a hidden textbox to keep the ID of the item. So if the textbox has a
ID
0 then it's an update, else it's an Add.

It's a little more complex than that, but it might get you started.

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...
>>I have a form that contains a number of fields, all of which have
validators. There are two submit buttons, one to update a record and one
to add a record. Because the only difference in validation is to make sure
someone is not using a username that is already in use, I would like to be
able to use all the other validators for both the add and update buttons.
However, because as far as I know a validator can only be in one
validationgro up, that does not help me (although if they haven't already,
I think it would be a great improvement for the next version of the .NET
framework). Does anybody have any suggestions on a good way to solve my
problem (having 2 copies of each validator would work and be very simple,
but I would hope for a more efficient way)? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/


Nov 5 '07 #3
"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...

[cross-posting removed]
a validator can only be in one validationgroup
This is one of the reasons that I never go anywhere near the validation
controls...

They're fine for basic stuff, but simply aren't flexible enough for more
complex validation.

For this, I'd just have one JavaScript function which accepts a parameter to
indicate whether the record is to be inserted or updated...

<script type="text/javascript">
function validateForm(ps trMode)
{
// common validation
if (pstrMode == 'New')
{
// extra validation for inserts
}
}
</script>

<asp:Button ID="cmdAdd" runat="server" Text="Add" OnCommand="Save _Command"
CommandArgument ="Add" OnClientClick=" return validateForm('N ew');" />
<asp:Button ID="cmdEdit" runat="server" Text="Edit" OnCommand="Save _Command"
CommandArgument ="Edit" OnClientClick=" return validateForm('E dit');" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #4
The custom validation control works fine for the oddball cases. NOT
using the validation controls because they don't always fill the need is
very short sited.

Since I don't know exactly what you are coding, I won't go so far as to
say that I could do anything you are doing the hard way (imo) with a
custom validation control. But, I'm pretty darn sure I could. Which
would save me time in the long run because I could use the regular
validation controls for the things that are common.

-----Original Message-----
From: Mark Rae [MVP] [mailto:ma**@mar kNOSPAMrae.net]
Posted At: Monday, November 05, 2007 5:51 PM
Posted To: microsoft.publi c.dotnet.framew ork.aspnet
Conversation: Sharing a Validator
Subject: Re: Sharing a Validator

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...

[cross-posting removed]
a validator can only be in one validationgroup
This is one of the reasons that I never go anywhere near the validation
controls...

They're fine for basic stuff, but simply aren't flexible enough for more

complex validation.

For this, I'd just have one JavaScript function which accepts a
parameter to
indicate whether the record is to be inserted or updated...

<script type="text/javascript">
function validateForm(ps trMode)
{
// common validation
if (pstrMode == 'New')
{
// extra validation for inserts
}
}
</script>

<asp:Button ID="cmdAdd" runat="server" Text="Add"
OnCommand="Save _Command"
CommandArgument ="Add" OnClientClick=" return validateForm('N ew');" />
<asp:Button ID="cmdEdit" runat="server" Text="Edit"
OnCommand="Save _Command"
CommandArgument ="Edit" OnClientClick=" return validateForm('E dit');" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #5
"Dave Bush" <da*******@dmbc llc.comwrote in message
news:0E91F9BC1F 98473596BB46B4A BC73EAC@OfficeV ista...
The custom validation control works fine for the oddball cases. NOT
using the validation controls because they don't always fill the need is
very short sited.
Not short sited (or even short-sighted) at all - there are many scenarios
which simply don't fit into the standard set of validation controls:
http://www.peterblum.com/VAM/ValMain.aspx

No doubt you could write your own JavaScript to fit into the Custom
Validator, but why bother when you can just write the precise JavaScript you
need...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '07 #6
That would be great for situations in which you did not care about
client-side validation, but I do want client-side validation (sort of). The
validators that differ between the Add and Edit is how you make sure a
duplicate username is not being created (when adding, it cannot exist
period, but with editing it can exist, but only as the current username of
the record being edited). I have written Validators (true validators that
inherits from the BaseValidator class) that use AJAX to check this
information on the server, because I do not want my users to have to
postback when filling out any of the form fields.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:e9******** ******@TK2MSFTN GP06.phx.gbl...
"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...

[cross-posting removed]
>a validator can only be in one validationgroup

This is one of the reasons that I never go anywhere near the validation
controls...

They're fine for basic stuff, but simply aren't flexible enough for more
complex validation.

For this, I'd just have one JavaScript function which accepts a parameter
to indicate whether the record is to be inserted or updated...

<script type="text/javascript">
function validateForm(ps trMode)
{
// common validation
if (pstrMode == 'New')
{
// extra validation for inserts
}
}
</script>

<asp:Button ID="cmdAdd" runat="server" Text="Add" OnCommand="Save _Command"
CommandArgument ="Add" OnClientClick=" return validateForm('N ew');" />
<asp:Button ID="cmdEdit" runat="server" Text="Edit"
OnCommand="Save _Command" CommandArgument ="Edit" OnClientClick=" return
validateForm('E dit');" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '07 #7
"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:Op******** ********@TK2MSF TNGP02.phx.gbl. ..
That would be great for situations in which you did not care about
client-side validation, but I do want client-side validation (sort of).
The validators that differ between the Add and Edit is how you make sure a
duplicate username is not being created (when adding, it cannot exist
period, but with editing it can exist, but only as the current username of
the record being edited). I have written Validators (true validators that
inherits from the BaseValidator class) that use AJAX to check this
information on the server, because I do not want my users to have to
postback when filling out any of the form fields.
Correct - that's how I do it too...

So what's the problem...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '07 #8
Hi, Nathan

The validators work regardless the button pressed, however, you can
define the ValidationGroup for the button and that button would
validate only with the specified validation group (or validators that
does not have the ValidationGroup specified)... well, at least
according to the docs -- I didn't make any test with it so far.

Regards,

Paulo Santos
http://pjondevelopment.50webs.com

On Nov 2, 6:38 pm, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
I have a form that contains a number of fields, all of which have
validators. There are two submit buttons, one to update a record and one to
add a record. Because the only difference in validation is to make sure
someone is not using a username that is already in use, I would like to be
able to use all the other validators for both the add and update buttons.
However, because as far as I know a validator can only be in one
validationgroup , that does not help me (although if they haven't already, I
think it would be a great improvement for the next version of the .NET
framework). Does anybody have any suggestions on a good way to solve my
problem (having 2 copies of each validator would work and be very simple,
but I would hope for a more efficient way)? Thanks.
--
Nathan Sokalski
njsokal...@hotm ail.comhttp://www.nathansokal ski.com/

Nov 8 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

195
8631
by: Torbjørn Pettersen | last post by:
As you might have noticed I'm trying to clean up my web site's HTML code. The way I do it is simply more or less redoing to complete site, testing it on a web server I have set up on my local network. I have downloaded, and installed CSE HTML Validator Pro, but I don't get the same results with that as I do with the online validator on W3.org. And I can't upload files to W3.org either, due to all the ASP code I use.
0
2235
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These controls and validators are then added to a table for display to the user. This code did seem to work originally, but now does not amd I am stumped as to why. There have been some code changes, but not to the methods below and I have pretty much...
6
5916
by: varlagas | last post by:
We disabled the antivirus software but the problem persists. Any clues? Many thanks in advance! Panagiotis Varlagas ======================================================================= 2005-07-28-10.39.02.015001 Instance:DB2 Node:000 PID:1568(db2syscs.exe) TID:2440 Appid:0A00153A.C90B.050728083720
8
7839
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
40
5620
by: VK | last post by:
Hi, After the response on my request from W3C I'm still unclear about Tidy vs. Validator discrepansies. That started with <IFRAME> issue, but there is more as I know. Anyway, this very basic HTML page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html401/strict.dtd"> <html> <head>
2
4544
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validator to each control as needed, but the validators are not firing when I click submit. The submit button was placed at design time and its causesvalidation property is set to true. Can someone tell me if something is missing from my code? Thank you. 1. Code to add dynamic control works fine and I get the Id of the textbox...
6
2490
by: yaru22 | last post by:
I'd like to create a program that validates bunch of urls against the w3c markup validator (http://validator.w3.org/) and store the result in a file. Since I don't know network programming, I have no idea how to start coding this program. I was looking at the python library and thought urllib or urllib2 may be used to make this program work.
8
4853
by: mc | last post by:
I would like to be able to send from an ASP.NET page an email which when recieved takes the form of a "Sharing Invitation for a RSS Feed" (http://office.microsoft.com/en-us/outlook/HA101595391033.aspx) I've found a MSDN article about it (http://msdn2.microsoft.com/en-us/library/bb176432.aspx) but that example is presented as a vb(a) script from within outlook. Can this functionality be emulated from sending an email from C#? TIA
37
3683
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry over" when there are <br /tags involved...??? I've tried using <p style="font-weight: bold;"></p>, I've tried <blockquote></blockquote>...I just can't figure how I'm supposed to get the <b></btags to work for all the lines! Surely there must be...
0
9577
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.