2011-02-02 7 views
1

현재 asp:linkbutton을 사용하여 전자 메일을 보내고 보내는 작은 양식이 있습니다.ASP.NET 및 JQuery | 제출시 jQuery LightBox 표시

사용자가 전체 게시물이 아닌 양식을 클릭하면 "제출해 주셔서 감사합니다."라는 라이트 박스를 대신 표시하고 싶습니다.

최상의 솔루션은 무엇입니까?

답변

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

관련 문제