This is a migrated thread and some comments may be shown as answers.

[Solved] client side validation

3 Answers 148 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 18 Jun 2008, 11:25 AM
Hi,
I'm having a problem with a simple client side validation. I have a check-box 'I agree' disclaimer and the form cannot be submitted until the box is checked. The javascript for this is:

function checkValid(){
        var chk =  document.getElementById('<%= chkValid.ClientID %>');
        if (chk.checked){
            return true;
        }else{
            alert('you must agree to the disclaimer in order to save');
            return false;
        }
       
    }

I then set the 'onclick' attribute of the asp:button to use the function.

This works fine until the radAjax control is used, then the callback is not fired.

I tried using the RadAjax example in the help file but find that the documentation is incorrect for version 2008.1.528.20 as the documentation refers to the "OnRequestStart" event but the control uses "ClientEvents-OnRequestStart".

Also the statement to get the clientid of the control that fired the ajax request is 

var eventTarget = eventArgs.EventTarget;

which is wrong and happens to be 

var

eventTarget = eventArgs.get_eventTarget();

The button I am using has an ID of "cmdSave" and is in the container of a master form. This means the clientID of the control obtained by using 

<%= cmdSave.ClientID %> produces ctl00_ContentPlaceHolder1_cmdSave

while the clientID returned from eventArgs.get_eventTarget(); is 

ctl00$ContentPlaceHolder1$cmdSave.

I would suggest that the help section on RadAjax needs to be rewritten and especially with client side validation.

Could you please tell me how I can run my simple javascript function as described above.

Regards

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 20 Jun 2008, 01:10 PM
Hi Roger,

Thank you for contacting us. I've created a simple application which should answer your question. Please check the example and see if it helps.

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Roger
Top achievements
Rank 1
answered on 21 Jun 2008, 12:59 AM
Hi Nikolay,

thanks for your example but it doesn't even contain a RadAjaxManager control.

My application works perfectly when not using RadAjaxManager.

It is only when using RadAjax that the button becomes locked when trying to submit. The validation using the javascript to check the checkbox works fine, it is the submit action of the button that is blocked by the RadAjaxManager.

The only way I have found to get over this problem of RadAjaxManager is to do a server side validation check.

Regards
0
Nikolay Rusev
Telerik team
answered on 23 Jun 2008, 01:14 PM
Hello Roger,

Thank you for getting back to us. Sorry if I did not understand you completely. I assume that you need to listen for the OnRequestStart event and check if the checkbox is checked or not. If it is checked you would like to proceed the request, otherwise to cancel it.

I modified the application from my last post to detect the OnRequestStart event raising and when it is fired an appropriate action is taking place.

Best regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Ajax
Asked by
Roger
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Roger
Top achievements
Rank 1
Share this question
or