473,385 Members | 1,492 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,385 software developers and data experts.

validating portions of asp.net page.

ani
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..
Nov 18 '05 #1
7 1577
All validators will fire on a submit unless they have been enabled. One way
I've found around this, or to set CausesValidation=False for one of the
submit buttons, and do it's validations on the server side. Not really the
cleanest solution since you forgoe the advantages of the validators.

However, you can't disable a certain set of validators on a submit, since
they fire before the postback. Perhaps you can disable a set of validators
based on some condition during page_load. That might not work for your
solutions though.
But ... May I ask why you're using two buttons to submit two different
controls ?

"ani" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

Nov 18 '05 #2
The easiest way would be adding code at the beginning of Button_Click event.
You can write a bool Private function to do this. If the function returns
false, then you can throw a new exception and catch it in the Button_Click,
and print some message to a label control.

Prodip Saha
"ani" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

Nov 18 '05 #3
ani
Thanks for the response.

This is a search page that i am working on and I have one
button for each text box that I need to validate. There
are two textboxes and each has got its own button to
search. How do I validate each of the controls for two
different submit buttons.
Thanks..


-----Original Message-----
All validators will fire on a submit unless they have been enabled. One wayI've found around this, or to set CausesValidation=False for one of thesubmit buttons, and do it's validations on the server side. Not really thecleanest solution since you forgoe the advantages of the validators.
However, you can't disable a certain set of validators on a submit, sincethey fire before the postback. Perhaps you can disable a set of validatorsbased on some condition during page_load. That might not work for yoursolutions though.
But ... May I ask why you're using two buttons to submit two differentcontrols ?

"ani" <an*******@discussions.microsoft.com> wrote in messagenews:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

.

Nov 18 '05 #4
I just went through that having two user controls on a page and wanting to
validate only the set of controls associated with the user control
containing the button that was clicked.

The following article was very helpful.
http://msdn.microsoft.com/library/de...pplusvalid.asp

What I basically came up with is:
Validators can be disabled on the client side using javascript, but will
still be evaluated when the form is posted back. Therefore you need a method
of determining which validators were disabled on the client side and disable
the same ones on the server side.
In my case I was working with editable datagrids and the validators were
contained in them. The clientId of all the grid's child controls includes
the ID of the datagrid.
In the OnMouseDown event of the 'submit' button I call a javascript function
and pass it the id of the datagrid.
The javascript function would loop through all the validators on the page
and enable only those whose id (ClientID on server side) contains the id
passed to the function.
A comma separated list of enabled validators is placed in a hidden text box.

Then on the server side in the page load event (if postback), I retrieve the
list of enabled validators from the hidden text box enable the validators in
the list and disable all others, before any are evaluated.

HTH.
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"ani" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

Nov 18 '05 #5
This concept is known as "Validation Groups" and will be a feature of
ASP.NET 2.0.

Until then, several third party products provide this feature. Mine is
"Professional Validation And More".
(http://www.peterblum.com/vam/home.aspx). With it, you simply define a name
for each group of controls and their related submit button. Assign that name
to the Group property on the validators and the button. It works fully on
the client side without writing any additional code.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com

"ani" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

Nov 18 '05 #6
ani
Could you please give me a sample.

Thanks.

-----Original Message-----
I just went through that having two user controls on a page and wanting tovalidate only the set of controls associated with the user controlcontaining the button that was clicked.

The following article was very helpful.
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnaspp/html/aspplusvalid.asp
What I basically came up with is:
Validators can be disabled on the client side using javascript, but willstill be evaluated when the form is posted back. Therefore you need a methodof determining which validators were disabled on the client side and disablethe same ones on the server side.
In my case I was working with editable datagrids and the validators werecontained in them. The clientId of all the grid's child controls includesthe ID of the datagrid.
In the OnMouseDown event of the 'submit' button I call a javascript functionand pass it the id of the datagrid.
The javascript function would loop through all the validators on the pageand enable only those whose id (ClientID on server side) contains the idpassed to the function.
A comma separated list of enabled validators is placed in a hidden text box.
Then on the server side in the page load event (if postback), I retrieve thelist of enabled validators from the hidden text box enable the validators inthe list and disable all others, before any are evaluated.

HTH.
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"ani" <an*******@discussions.microsoft.com> wrote in messagenews:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

.

Nov 18 '05 #7
On server side:

Give all your validators a grouping id. Such as Group1_val1, Group1_val2,
Group2_val1, Group2_val2.

Add an OnMousedown event to the button (I did it in Page_Load) that will
cause validation for each group.
btnGroup1.Attributes.Add("OnMousedown","EnableVali dators("Group1_);")
btnGroup2.Attributes.Add("OnMousedown","EnableVali dators("Group2_);")

Make sure your page contains a hidden textbox who's id=txtEnableVals.

Add the following routine to your project in a class or module so it can be
used for whatever page you like:

Public Sub EnableServerValidators(ByVal strEnableList As String, ByVal
objVals As System.Web.UI.ValidatorCollection)
'v 1/2/04

'Call in page load event on postback.

'Enables validators in the comma delimited string 'strEnableList' and
disable all others

'For more info see 'AddDgrdEnableValidators' and javascript function
'EnableValidators'

'If the list is empty, all validators are disabled

'Enumeration taken from help/MSDN articles.

Dim strEnableVals() As String

Dim strVal As String

Dim shrIdx As Short

Dim shrVals As Short

strEnableVals = Split(strEnableList, ",")

shrVals = UBound(strEnableVals)

' Get 'Validators' of the page to collVals.

Dim collVals As System.Web.UI.ValidatorCollection = objVals

' Get the Enumerator.

Dim enumVals As IEnumerator = collVals.GetEnumerator()

While enumVals.MoveNext()

'enumVals.Current have all the expected properties, methods expected of
validators.

'They just don't show up with intellisense

strVal = enumVals.Current.clientid

For shrIdx = 0 To shrVals

If strVal = strEnableVals(shrIdx) AndAlso enumVals.Current.enabled = False
Then

enumVals.Current.enabled = True

Exit For

End If

Next

If shrIdx > shrVals AndAlso enumVals.Current.enabled = True Then

enumVals.Current.enabled = False

End If

End While

End Sub

Add the following to the page_load event:

If IsPostBack Then

EnableServerValidators(txtEnableVals.Value, Page.Validators)

End If
Client side:
function EnableValidators(strEnable)

{

/************************************************** ********************

v 1/2/04

Enable validators whose clientid contains the string passed in strEnable

Disable all others.

This is done utilizing the .NET supplied validator array 'Page_Validators'
and

'ValidatorEnable' function.

Useful for when there are multiple submit buttons on a page and different

validators should be enabled for each button.

The buttons' OnMouseDown event should be:
OnMousedown="EnableValidators('stringToEnable');"

Usuall added by server side code

All validators should be enabled by design on server side.

Enabling on client side causes validators to validate so it is not desirable

to enable any validators on client side that should not be evaluated at that
time.

Since this only affects client side validation, the Enabled validators
clientid's

are passed back to the server through a hidden text box (txtEnableVals) so
they can be

Enabled prior to server side validation.

************************************************** *********************/

var i;

var strID;

var strEnableVals = "";

var txtEnable;
txtEnable = document.getElementById("txtEnableVals");

if (txtEnable != null)

{

for (i = 0; i < Page_Validators.length; i++)

{

strID = Page_Validators[i].id;

if (strID.indexOf(strEnable)>-1)

{

ValidatorEnable(Page_Validators[i], true);

if (strEnableVals != "")

{

strEnableVals += ",";

}

strEnableVals += Page_Validators[i].id;

}

else

{

ValidatorEnable(Page_Validators[i], false);

}

}

txtEnable.value = strEnableVals

}

}

When btnGroup1 causes the submit, only validators whose id contains 'Group1'
will be evaluated and likewise when btnGroup2 submits, only validators whose
id contains 'Group2' will be evaluated.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"ani" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Could you please give me a sample.

Thanks.

-----Original Message-----
I just went through that having two user controls on a

page and wanting to
validate only the set of controls associated with the

user control
containing the button that was clicked.

The following article was very helpful.
http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/dnaspp/html/aspplusvalid.asp

What I basically came up with is:
Validators can be disabled on the client side using

javascript, but will
still be evaluated when the form is posted back.

Therefore you need a method
of determining which validators were disabled on the

client side and disable
the same ones on the server side.
In my case I was working with editable datagrids and the

validators were
contained in them. The clientId of all the grid's child

controls includes
the ID of the datagrid.
In the OnMouseDown event of the 'submit' button I call a

javascript function
and pass it the id of the datagrid.
The javascript function would loop through all the

validators on the page
and enable only those whose id (ClientID on server side)

contains the id
passed to the function.
A comma separated list of enabled validators is placed in

a hidden text box.

Then on the server side in the page load event (if

postback), I retrieve the
list of enabled validators from the hidden text box

enable the validators in
the list and disable all others, before any are evaluated.

HTH.
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"ani" <an*******@discussions.microsoft.com> wrote in

message
news:03****************************@phx.gbl...
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..

Thanks..

.

Nov 18 '05 #8

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

Similar topics

5
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought...
6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
12
by: Claire Lescarret | last post by:
Hello, I have devoted my time to write valid html 4.01 strict, and CSS-1 and 2 *but* I also have to use third party's code for webcounter (StatCounter) and Google's SiteSearch, which are...
7
by: Armand Karlsen | last post by:
On one page of a site I'm doing for a college project, I have a feedback form: http://www.zen62775.zen.co.uk/Test/contact/contact_feedback.html All parts of this page validate, except for the...
5
by: DeMZed | last post by:
Hi, When validating my web site, I've got the following error : ------------------------------ Line 31, column 26: cannot generate system identifier for general entity "PHPSESSID" <a...
2
by: Raghu R | last post by:
From: "R. Raghuraman" <raghuraman@infosys.com> Subject: Problem with XMLValidatingReader? Date: 01 April 2004 11:46 Hi, I have a large xml file to process (~ 70 mb). I am trying to use...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
17
by: stathis gotsis | last post by:
Hello everyone, I am tying to come up with an elegant way to process some input data that come from a form. When the user hits the 'Submit' button, i want the form to appear again with the...
5
by: chadwick | last post by:
Hi everyone - I have a form that contains a TabControl object with 2 tab pages, TabPage1 and TabPage2. TabPage1 contains two text boxes and a cancel button, which closes the form. I would like...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.