473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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********@hotmail.com
http://www.nathansokalski.com/
Nov 2 '07 #1
8 1312
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********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP05.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
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********@hotmail.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********@hotmail.com
http://www.nathansokalski.com/

"ace_away" <ac*@away.comwrote in message
news:uS****************@TK2MSFTNGP06.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********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP05.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
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********@hotmail.com
http://www.nathansokalski.com/


Nov 5 '07 #3
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP05.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(pstrMode)
{
// 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('New');" />
<asp:Button ID="cmdEdit" runat="server" Text="Edit" OnCommand="Save_Command"
CommandArgument="Edit" OnClientClick="return validateForm('Edit');" />
--
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**@markNOSPAMrae.net]
Posted At: Monday, November 05, 2007 5:51 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Sharing a Validator
Subject: Re: Sharing a Validator

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP05.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(pstrMode)
{
// 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('New');" />
<asp:Button ID="cmdEdit" runat="server" Text="Edit"
OnCommand="Save_Command"
CommandArgument="Edit" OnClientClick="return validateForm('Edit');" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #5
"Dave Bush" <da*******@dmbcllc.comwrote in message
news:0E91F9BC1F98473596BB46B4ABC73EAC@OfficeVista. ..
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********@hotmail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:e9**************@TK2MSFTNGP06.phx.gbl...
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:eQ**************@TK2MSFTNGP05.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(pstrMode)
{
// 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('New');" />
<asp:Button ID="cmdEdit" runat="server" Text="Edit"
OnCommand="Save_Command" CommandArgument="Edit" OnClientClick="return
validateForm('Edit');" />
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '07 #7
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:Op****************@TK2MSFTNGP02.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...@hotmail.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...@hotmail.comhttp://www.nathansokalski.com/

Nov 8 '07 #9

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

Similar topics

195
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...
0
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...
6
by: varlagas | last post by:
We disabled the antivirus software but the problem persists. Any clues? Many thanks in advance! Panagiotis Varlagas ======================================================================= ...
8
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...
40
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...
2
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....
6
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...
8
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"...
37
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.