How to get rid of Page_ClientValidate() ?

A

Ante Perkovic

Hi,

I'm trying to make a client side validation in a datagrid. Here is
what I did:

in mypage.aspx, I put:
<script language=javascript>
function isItValid(){ // just testing the functionality
if (document.Form1.txtIme.value != "ok"){
alert("!= OK")
return false
}else{
alert("OK")
return true
}
}
</script>

and in codeBehind file, I put:

Private Sub dgRezervirano_ItemDataBound(ByVal sender As Object,
ByVal e As DataGridItemEventArgs) Handles dgRezervirano.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim btn as New Button()
btn = CType(e.Item.Cells(4).Controls(0), Button)
btn.Attributes("onclick") = "return isItValid()"

But, in html that is generated, I can see:
<input type="submit" name="dgRezervirano:_ctl4:_ctl0" value="ok"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" onclick="return
isItValid()" />

Looks like
if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
causes
onclick="return isItValid()"
to be ignored!(?)

How can I change this?

BTW, what is this Page_ClientValidate thing doing. How can I use it?

Thanks,

Ante
 
C

Christof Nordiek

Hi Ante,

If you want to supress the client validation provided by ASP.NET set the
CausesValidation Property of the Button to false:
btn.CausesValidation = False

Another way would be to use a CustomValidator ans set it's
ClientValidationFunction Property to the name of your Function ('isIfValid')

cn
 
A

Ante Perkovic

If you want to supress the client validation provided by ASP.NET set the
CausesValidation Property of the Button to false:
btn.CausesValidation = False

Another way would be to use a CustomValidator ans set it's
ClientValidationFunction Property to the name of your Function ('isIfValid')

cn

Thanks, Christof

I set btn.CausesValidation to False, but still have the problem! Now,
the code looks like this:

<script language="javascript">
function isItValid(){
alert(document.Form1.txtIme.value)
if (document.Form1.txtIme.value != "ok"){
alert("!= OK")
return false
}else{
alert("OK")
return true
}
}
</script>

in codeBehind:
....
btn.CausesValidation = False
btn.Attributes("onclick") = "isItValid()"
....

which results in this html being generated:
<script language="javascript">
function isItValid(){ ... // the same, that's OK
....
<input type="submit" name="dgRezervirano:_ctl6:_ctl0" value="OK"
onclick="isItValid()" ID="Submit9" />

As You can see, onclick now contains only "isItValid()". But, whan I
click it, nothing happens (not even the alert popup)!
This looks like javascript/html problem now (?)

I don't get it!

Ante Perkovic
 
W

William F. Robertson, Jr.

I think you really might want to look into what Chistof has to say about the
CustomValidator.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwebuiwebcontrolscustomvalidatorclasstopic.asp

specifically read about the ClientValidationFunction property to set your
own client validation function to it.

BTW, what is this Page_ClientValidate thing doing. How can I use it?

That is output by the framework to assist in calling the all the validators
for the page. I would suggest reading more about validation to use this
really cool and easy feature.

bill
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top