943,763 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 21022
  • ASP.NET RSS
Jul 15th, 2004
0

.net validation/javascript conflict

Expand Post »
Hi

I would like to run a javascript function (to confirm deletion) from a web control (asp:button) before posting back to the same page.

I have read about how to do this in several places (mybutton.attributes.add... )

However, the fact that I have asp.net validation controls on my page means that I automatically end up with two onclick attributes in my HTML and the javascript function is not called.

Has anybody encountered (and hopefully solved) this?

Thanks in advance

Duncan
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsilander is offline Offline
2 posts
since Jul 2004
Jul 20th, 2004
0

Re: .net validation/javascript conflict

Quote originally posted by dsilander ...
Hi

I would like to run a javascript function (to confirm deletion) from a web control (asp:button) before posting back to the same page.

I have read about how to do this in several places (mybutton.attributes.add... )

However, the fact that I have asp.net validation controls on my page means that I automatically end up with two onclick attributes in my HTML and the javascript function is not called.

Has anybody encountered (and hopefully solved) this?

Thanks in advance

Duncan
Hi
use custom validator for the purpose.

pls get back to me if its not solved.

thnks n regards
siddartha
Reputation Points: 11
Solved Threads: 0
Newbie Poster
siddartha_pal is offline Offline
8 posts
since Jun 2004
Jul 20th, 2004
0

Re: .net validation/javascript conflict

siddartha_pal, I think you misunderstand the issue.

dslander, what type of validation controls are you using? Can you just incorporate your onclick logic to the javacript for the validation?
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 20th, 2004
0

Re: .net validation/javascript conflict

I am using both required field validators and regular expression validators.

I could probably work around the issue by using custom validators but I would rather do it with the controls I have if at all possible (it's easier & tidier).

If I resort to using custom validators then I'd be as well coding the whole thing (validation & confirmation) in the javascript onclick event. I could do this but would rather use the more concise & specific .net controls if I can.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsilander is offline Offline
2 posts
since Jul 2004
Jul 27th, 2004
0

Re: .net validation/javascript conflict

Quote originally posted by dsilander ...
I am using both required field validators and regular expression validators.

I could probably work around the issue by using custom validators but I would rather do it with the controls I have if at all possible (it's easier & tidier).

If I resort to using custom validators then I'd be as well coding the whole thing (validation & confirmation) in the javascript onclick event. I could do this but would rather use the more concise & specific .net controls if I can.

hi there
I am not getting how u have two onclick attributes? and why u need two onclick there.
I think when your javascript function will return true only then server side event handler should execute. Seems I am anot able to get u properly.

thnks
Reputation Points: 11
Solved Threads: 0
Newbie Poster
siddartha_pal is offline Offline
8 posts
since Jun 2004
Jul 28th, 2004
0

Re: .net validation/javascript conflict

I have the same probleb with javasecript code using custom validator
i tried to make the return to true but it failed too
so anyone can give me a hand on this problem or send me a Sample
Reputation Points: 10
Solved Threads: 0
Newbie Poster
haniebrahim is offline Offline
2 posts
since Jul 2004
Sep 15th, 2004
0

Re: .net validation/javascript conflict

I came across this problem too.

This simple solution is probably enough:
- disable validation on your delete button (causesvalidation="false")
- add the 'onclick' event as normal using the Attributes property in your code behind file.

Setting causesvalidation to false means .net won't put in it's own 'onclick' method.

For my application, the delete doesn't require any validation (it just deletes the current item), and I think this will apply in the majority of situations. Hopefully those where some form of validation is required, maybe it's simple enough to write custom jscript.

I think it's a bit of a short-fall in the current webforms implementation.

Troy.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Hardcoder is offline Offline
1 posts
since Sep 2004
May 28th, 2005
0

Re: .net validation/javascript conflict

Same problem happened to me and I've found a solution..

Now HERE IS MY SOLUTION;
1) Change EnableClientScript settings to FALSE for each validation rule. (Custom or Regular doesn't matter)
This will post the page back and validate fields at server level.

2) Place your code which you would like to process, if all fields are valid to between followin if statement;
if Page.IsValid then
'Your code
end if

And this worked fine for me, I am positive it is going to work for you too,..

Thanks,
Mert..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cmert is offline Offline
1 posts
since May 2005
May 31st, 2007
0

Re: .net validation/javascript conflict

Click to Expand / Collapse  Quote originally posted by cmert ...
Same problem happened to me and I've found a solution..

Now HERE IS MY SOLUTION;
1) Change EnableClientScript settings to FALSE for each validation rule. (Custom or Regular doesn't matter)
This will post the page back and validate fields at server level.

2) Place your code which you would like to process, if all fields are valid to between followin if statement;
if Page.IsValid then
'Your code
end if

And this worked fine for me, I am positive it is going to work for you too,..

Thanks,
Mert..

I am having that same problem too regarding with the .net validator and javascript ...

after i have try your suggestions it didn't work fine for me....

cause im using a java-based calendar and a required field validator
although the calendar is working but whenever it clicks.. for example clicking the year (or month) it skips by 3 , by 4 , by 5 and so on....

and whenever i checked the error.. this is what i've got

----length is 'null' or not an object

how come that is null? and why it is null?

can anyone knows why are those two conflict?

???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
airyce is offline Offline
1 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: .Net development environment bug w/ asp code?
Next Thread in ASP.NET Forum Timeline: converting vb6 to asp.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC