Server side event doesn't get called if Ajax and OnClientclick added

6 posts, 0 answers
  1. Shubha Singh
    Shubha  Singh  avatar
    6 posts
    Member since:
    Oct 2012

    Posted 29 Oct 2009 Link to this post

    Below is my scenario:

    Scenario:

    1. I have one telerik:RadAjaxManager which has telerik:AjaxSettings. In it, AjaxControlID is a button Id and AjaxUpdatedControl is a table which contains that button along with few textboxes, requiredfieldvalidators for them and one server side button.

    2. The button has onclientclick and onclick events registered.

    3. Onclientclick event calls a simple javascript function which does some validation of form data and returns true or false. (OnClientClick="return ValidatePage();")

    4. Onclick event calls some server side implementation.

     Behavior:

    1. When a button is clicked,  requiredfieldvalidators (only checks if data is entered) gets fired.

    2. When data is entered in the textboxes, javascript function 'ValidatePage()' (checks if VALID data is entered) gets fired.

    3. When ValidatePage() returns false, server side event doesn't get fired.(Which is desired behavior)

    4. When ValidatePage() returns true, still server side event doesn't get fired.(Which is not desired behavior)

    5. When OnclientClick event registration is removed, the server side event gets fired through AJAX after entering data in the textboxes.

    6. When button is moved out of the table, both, the javascript function and the server side event gets fired but normal postback occurs.

    Desired behavior:

    1. First requiredfieldvalidators should get fired.

    2. Then 'ValidatePage()' should get fired. If it returns false, it should restrict server side call. If it returns true, server side event should get called through AJAX.

    Please let me know if you have any comments on it.

    Regards,

    Shubha
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 02 Nov 2009 Link to this post

    Hello Shubha,

    RadAjax changes submit behavior of the buttons to postback through script/__doPostBack../.
    Due to this fact all the script that you append OnClientClick it is inserted right before submit script.
    In this case if you have return in front of the submit script it will not be executed regardless whether your return type is true or false. I.e. the following wont cause the alert to be called: onclick="return true;alert(1);"

    To workaround this behavior you should construct the script as follow:
    1.<asp:Button runat="server" ID="Button1" 
    2.        OnClientClick="if(!CallYourFunction()) { return false; };"/>


    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Shubha Singh
    Shubha  Singh  avatar
    6 posts
    Member since:
    Oct 2012

    Posted 06 Nov 2009 Link to this post

    Hi Nikolay,

    Thanks for the reply. By applying solution you suggested, the server side method does get called properly but this fix spawns another problem. There are few validators and validationSummary control inside my RadAjaxPanel which has ShowMessageBox="true". This error messagebox pops up twice when the validator fails on button click attempt. I tried EnableClientScript="false" but still it pops up twice.
    Is there any way to prevent this?

    Regards,

    Shubha
  4. Shubha Singh
    Shubha  Singh  avatar
    6 posts
    Member since:
    Oct 2012

    Posted 06 Nov 2009 Link to this post

    My bad. I was calling Page_ClientValidate('bookingValidationGroup'); through my javascript function. :P. It's working fine now.
    Sorry for the inconvenience.
  5. Mahesh
    Mahesh avatar
    6 posts
    Member since:
    Jan 2013

    Posted 04 Feb 2013 Link to this post

    i have same problem and using this post i able to call server side function but i got error during execution code
    on my save button i m doing
    1. save data in database
    2. Reset Controls
    3. load updated controls
    4. set focus on my first control

    my error message is

    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.<br>Details: Error parsing near 'older1_txtGroupName|<script type="text/j'.
  6. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 07 Feb 2013 Link to this post

    Hello Mahesh,

    Could you please elaborate a little bit more on your scenario? As far as I can see you have a parse error in your code behind. Sending us your code declaration with the related code behind will help us to pinpoint the reason for that behavior.

    Greetings,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top