Validate before JScript

P

Peter

ASP.NET 1.1

I have WebForm button with JScript, but I want to validate the form before
the JScript runs when the user clicks on the button, how to I do that?

this.butCreateLetter.Attributes.Add("onClick", "return CreateLetter();");



Thank You


Peter
 
K

Karl Seguin [MVP]

You pretty much have to output the javascript you want to run inside your
button's event handler.

Karl
 
M

Mark Newmister

this.butCreateLetter.Attributes.Add("onClick", "if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); return
CreateLetter();");
 
P

Peter

Mark Newmister said:
this.butCreateLetter.Attributes.Add("onClick", "if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); return
CreateLetter();");

Thank You very much.

I have one more question

If validation fails how do I stop it from running the CreateLetter()
function?


Thanks
 
K

Karl Seguin [MVP]

that'll only work for client-side validation. Ie, it won't work in firefox..

Karl
 
P

Peter

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
that'll only work for client-side validation. Ie, it won't work in
firefox..

Karl

yes I am aware of it, this webpage is for Intranet and this webpage uses
ActiveX to open Word template so user has to use IE.

I have found the solution to stop executing JScript when validation fails:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false } else {return
CreateLetter(); }} ");


Thank you for all the help!!!
 
M

Mark Newmister

that'll only work for client-side validation.

I thought that was what he wanted.

Hmmm...works for me using this FF version:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111
Firefox/1.5
 
M

Mark Newmister

....however, I just realized that I'm using 2.0 and he mentioned 1.1. Would
this be the difference?
 
K

Karl Seguin [MVP]

Yes, validators in 1.1 won't work in Firefox, in 2.0 they do (client-side
that is).

Looks like you are right, IE only on an intranet..though I see no where in
the original post where that was stated :p lucky guess ;)

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top