?
Solved

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

Posted on 2009-04-04
4
Medium Priority
?
664 Views
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!
0
Comment
Question by:vbhargav80
  • 2
4 Comments
 
LVL 14

Assisted Solution

by:amar31282
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

0
 
LVL 4

Expert Comment

by:mahadevan_v
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


0
 

Author Comment

by:vbhargav80
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?
0
 
LVL 4

Accepted Solution

by:
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;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.myForm.time.value=xmlHttp.responseText;
//This statement get value from the server page and sets it to control add a client validation for checking the return value
      }
    }
  xmlHttp.open("POST","time.asp",true);
  xmlHttp.send(null);
  }



Check this link for examples

http://www.w3schools.com/Ajax/ajax_example.asp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 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