473,396 Members | 1,975 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.

Using Javascript and Validation controls

Hello,

I'm creating an application in ASP.NET 1.1. I need to check whether at least
one checkbox in my datagrid has been checked. To do this, I'm using
Javascript - I'm adding this code to Page_Load event:

Dim iCount As Int32
Dim sClientSideValidate As New StringBuilder
iCount = dgReport.Items.Count
For i As Int32 = 2 To iCount + 1
If Not i = iCount + 1 Then
sClientSideValidate.Append("dgReport__ctl" & i & "_chkConf.checked ||")
Else
sClientSideValidate.Append("dgReport__ctl" & i & "_chkConf.checked")
End If
Next
btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you want
to submit change?');}")
'RELEASE RESOURCES
sClientSideValidate = Nothing

This works great. The problem is that if I use this script, my other ASP.NET
validation controls on this page no longer work. I can see why - since the
Javascript runs on button onclick (client) event, I guess all other
Javascript on this page is ignored.

I wonder - is there a way to use both - javascript validation and ASP.NET
1.1 validation contols on the same page, or I have to put all validation in
JS?

I would appreciate your help.

Thank you,

--
Peter Afonin
Mar 14 '07 #1
6 3257

Peter Afonin wrote:
btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you want
to submit change?');}")
'RELEASE RESOURCES
sClientSideValidate = Nothing

This works great. The problem is that if I use this script, my other ASP.NET
validation controls on this page no longer work. I can see why - since the
Javascript runs on button onclick (client) event, I guess all other
Javascript on this page is ignored.

I wonder - is there a way to use both - javascript validation and ASP.NET
1.1 validation contols on the same page, or I have to put all validation in
JS?
Hi,
I think your "return confirm(..." breaks off the client-side
validation of ASP validation controls.

Try to replace
return confirm('... to submit change?');

with
if (confirm('... to submit change?')) return false;
Maybe it helps.

Mar 16 '07 #2

marss wrote:
if (confirm('... to submit change?')) return false;
I mean
if (!confirm('... to submit change?')) return false;

Mar 16 '07 #3
Thank you very much, you were correct! Without return everything
works.

Peter

On Mar 16, 7:25 am, "marss" <marss...@gmail.comwrote:
PeterAfoninwrote:
btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you want
to submit change?');}")
'RELEASE RESOURCES
sClientSideValidate = Nothing
This works great. The problem is that if I use this script, my other ASP.NET
validation controls on this page no longer work. I can see why - since the
Javascript runs on button onclick (client) event, I guess all other
Javascript on this page is ignored.
I wonder - is there a way to use both - javascript validation and ASP.NET
1.1 validation contols on the same page, or I have to put all validation in
JS?

Hi,
I think your "return confirm(..." breaks off the client-side
validation of ASP validation controls.

Try to replace
return confirm('... to submit change?');

with
if (confirm('... to submit change?')) return false;
Maybe it helps.

Mar 16 '07 #4
I'm still having a problem here, because I do need to use 'return
false' at the end:

btnSubmit.Attributes.Add("onClick", "if (!(" &
sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you
want
to submit change?');return false;}")

If I use it - my other validation controls are dead.

I wonder - are there any substitutes for 'return false'?

Thank you,

Peter

On Mar 16, 7:25 am, "marss" <marss...@gmail.comwrote:
PeterAfoninwrote:
btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you want
to submit change?');}")
'RELEASE RESOURCES
sClientSideValidate = Nothing
This works great. The problem is that if I use this script, my other ASP.NET
validation controls on this page no longer work. I can see why - since the
Javascript runs on button onclick (client) event, I guess all other
Javascript on this page is ignored.
I wonder - is there a way to use both - javascript validation and ASP.NET
1.1 validation contols on the same page, or I have to put all validation in
JS?

Hi,
I think your "return confirm(..." breaks off the client-side
validation of ASP validation controls.

Try to replace
return confirm('... to submit change?');

with
if (confirm('... to submit change?')) return false;
Maybe it helps.

Mar 19 '07 #5

Peter Afonin wrote:
I'm still having a problem here, because I do need to use 'return
false' at the end:
Why? You should to use 'return' only if "your condition"=false
>
btnSubmit.Attributes.Add("onClick", "if (!(" &
sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you
want
to submit change?');return false;}")

If I use it - my other validation controls are dead.

I wonder - are there any substitutes for 'return false'?

Thank you,

Peter
Run your project and look through the page source.
You can find that the Button control is rendered as a html like this:

<input type="submit" name="btnSubmit" value="Submit" onclick="if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
language="javascript" id="btnSubmit" />

Here "if (typeof(Page_ClientValidate) == 'fu..." is the script to call
the client-side validation. If you add one more event handler for
client-side "onclick" event it will be added right before above
script.
Example:

btnSubmit.Attributes.Add("onclick", "return false;");

causes next html to be rendered:
.... onclick="return false;if (typeof(Page_ClientValidate) ==
'functio...

The "return" breaks off the next code execution. So you should write
your script in the way that does not interrupt the validation if
everything is ok.
Try something like this:

"if (!(" & sClientSideValidate.ToString & ") || confirm('...?'))
return false;"

Mar 20 '07 #6
Thank you, I'll try this.

Peter

On Mar 20, 4:24 am, "marss" <marss...@gmail.comwrote:
PeterAfoninwrote:
I'm still having a problem here, because I do need to use 'return
false' at the end:

Why? You should to use 'return' only if "your condition"=false
btnSubmit.Attributes.Add("onClick", "if (!(" &
sClientSideValidate.ToString
& ")){ return confirm('You have not selected any DRs. Are you sure you
want
to submit change?');return false;}")
If I use it - my other validation controls are dead.
I wonder - are there any substitutes for 'return false'?
Thank you,
Peter

Run your project and look through the page source.
You can find that the Button control is rendered as a html like this:

<input type="submit" name="btnSubmit" value="Submit" onclick="if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
language="javascript" id="btnSubmit" />

Here "if (typeof(Page_ClientValidate) == 'fu..." is the script to call
the client-side validation. If you add one more event handler for
client-side "onclick" event it will be added right before above
script.
Example:

btnSubmit.Attributes.Add("onclick", "return false;");

causes next html to be rendered:
... onclick="return false;if (typeof(Page_ClientValidate) ==
'functio...

The "return" breaks off the next code execution. So you should write
your script in the way that does not interrupt the validation if
everything is ok.
Try something like this:

"if (!(" & sClientSideValidate.ToString & ") || confirm('...?'))
return false;"

Mar 20 '07 #7

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

Similar topics

0
by: Matthias Lohrer | last post by:
Hi, I'm playing around with the possibilities of Page.ParseControl. Thanks to Kirk Allen Evans I got my example running (Posting Juli, 17, "Re: Generating ASP.NET-Controls with XSLT...
7
by: Tom | last post by:
I know how to use these great controls. They work very well. But is there a method or property I can use to set the focus to the field that is in error. For example... If I have a page with 5...
2
by: Herve MAILLARD | last post by:
Hi, J'ai un bouton ASPX qui doit déclencher un script java. I have an ASPX button running a javascript. To do this, I have added in the codebehind :...
4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
5
by: M | last post by:
Hi, it's possible to append a custom action to a client-side verification of a validation control ? I have a validator summary control that shows (automatically) a message box if the validation...
2
by: Roh | last post by:
Hi, Can we use Javascript and .Net Validation controls on the same page. If yes how? Please provide some examples which will help me a lot....thanks.
3
by: Jon B | last post by:
Hi There! I noticed that Validation Controls uses Client Side JavaScript to do that validation. Will these controls still works on JavaScript disabled browsers? How to validate on those...
1
by: APA | last post by:
Well, I've figured out a way around this mess. I have no idea why it doesn't work the way I think it should but I do know how to get it to work. The scenario is that I have a form that has one...
5
by: Peter Afonin | last post by:
Hello, I'm not an expert in Javascript, so I'm seeking an advice. As I mentioned in my previous post, I use Javascript to check whether at least one checkbox in the datagrid has been checked....
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.