?
Solved

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

Posted on 2009-04-04
4
Medium Priority
?
647 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
[X]
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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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 …
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 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