2011-02-02 10 views
1

現在、私はasp:linkbuttonを使用して電子メールを送信して送信する小さなフォームを持っています。ASP.NET&JQuery |サブミット時にjQueryライトボックスを表示

代わりに、完全なポストバックではなくフォームをクリックしたときに、「送信していただきありがとうございます」というライトボックスを表示したいと考えています。

最適なソリューションは何ですか?

答えて

2

フォームを投稿してライトボックスを呼び出さないようにするには、イベントをインターセプトする必要があります。このような何か:

クレート新しいハンドラmyHandler.ashx次のようになります:サーバー側で、その後

$('#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; 
} 

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); 

    } 
+0

意志をまだ '保護され、ボイドSubmit_Clickを打ちます(オブジェクト送信者、EventArgs e) 'フォームを送信するコードの背後にある? – balexander

+0

いいえ、それはありません。 $ .post – Victor

+0

ボールを使用して非同期呼び出しを行う必要があります。私はいつも更新パネルを使用していたので、これを行う方法はわかりません。おそらく私は代わりにその方法を行うことができますいくつかのコードやリンクを提供できますか? – balexander

関連する問題