balexander
balexander

Reputation: 24349

ASP.NET & JQuery | Show jQuery LightBox on Submit

Currently I have a small form that uses a asp:linkbutton to submit and send out an email.

I want to instead display a lightbox saying "Thank you for your submission" when the user clicks the form rather than a full post back.

What is the best solution?

Upvotes: 1

Views: 1282

Answers (1)

Victor
Victor

Reputation: 4721

You will need to intercept the event to prevent the form from posting, and then calling your lightbox. Something like this:

$('#yourbutton').bind('click', function() {
   event.preventDefault();
   //do an asynchronous post here
   $.ajax({
      type: 'POST',
      url: 'http://yoursite.com/yourhandler.ashx',
      data: {param1:value1,param2:value2}, //if needed
      success: function(data) {
         //here you check for the data returned to be valid, not required
         $('#yourDiv').show(); //show a div here or you can just show a lightbox
      },
      dataType: 'json'
   });

   return false;
}

then on the server side:

crate a new Handler myHandler.ashx that would look like this:

public class myHandler : IHttpHandler
  {

    public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "text/plain";

      //this is not required if you are not passing any parameters
      string param1 = context.Request["param1"].ToString();
      string param2 = context.Request["param2"].ToString();
      string output = "";

      //here you would insert your function that would send the email or whatever it is that your function does.

      //set the output
      output = "{Success:true"}";

      context.Response.Write(output);

    }

Upvotes: 2

Related Questions