Solved LinkButton - DO an ajax request and then submit the form

Posted on 2009-04-04
Last Modified: 2012-06-27
Dear experts,

I have a form and to submit the form I am using a linkButton. My linkbutton also does some client side validation before submitting the form. A requiremtn has now come in that I do some server side validation before submitting the form. This means the linkbutton first needs to send an ajax request (without doing a page refresh) and based on the result give the user a modal popup. On the modal popup if the user clicks continue, i need to submit the form otherwise cancel submitting the form.

I am really stuck and have no idea if/how thsi can be achieved. Please help!
Question by:vbhargav80
  • 2
LVL 14

Assisted Solution

amar31282 earned 100 total points
ID: 24067971
you need to use javascript as
    function TestFunction(data)
        var flag = true;
        if( data == "") 
            flag = confirm("You have not entered any name. This will result in all the records.\nDo you want to Continue...");
        return flag;
In link button use
OnClientClick="return TestFunction(document.getElementById('Simple_Search_Faculty_Name_Input').value);"

Open in new window


Expert Comment

ID: 24068387
I will give you an overview of how it can be done ..

1. write a javascript function and attach it to the link button ,
2. In that function send an ajax request to the page where you have the server side validation.
    Return a value from the server page
3. On the function which process the response, compare the value from server , then open a modal dialog using showmodal dialog function
vReturnValue = window.showModalDialog()
4. now check the return value from the modal for submitting or cancel page progress


Author Comment

ID: 24069394
My LinkButotn already has some javascript attached to it which is doing the client side validation. How can I attach 2 different pieced of javascript to it, 1 that does client side and 1 that does server side?

Accepted Solution

mahadevan_v earned 400 total points
ID: 24070787
no need to add another function

after the client side validation create an ajax request to the server page

function ajaxFunction()
// DO YOUR CLIENT VALIDATIIOIN//if all your client validations are passed call the server page with validations using the below code..

var xmlHttp;
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
catch (e)
  // Internet Explorer
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  catch (e)
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    catch (e)
      alert("Your browser does not support AJAX!");
      return false;
//This statement get value from the server page and sets it to control add a client validation for checking the return value

Check this link for examples

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can I command line build a C# application? 6 40
Finding Events logs for IIS website that restarts 2 14
IEnumerable<T> to a List<T> 8 37
Input parameteres to DragOver 2 19
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question