Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


asp.net LinkButton - DO an ajax request and then submit the form

Posted on 2009-04-04
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Assisted Solution

amar31282 earned 400 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 1600 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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