[WebMethod()]
public static string SaveRequest()
{
StringWriter _writer = new StringWriter();
HttpContext.Current.Server.Execute("frmGenerateRequests.aspx", _writer);
string html = _writer.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = "GenerateDocument" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
strHTMLContent.Append(html.ToString());
HttpContext.Current.Response.Write(strHTMLContent);
//HttpContext.Current.Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
HttpContext.Current.Response.Flush();
return "Success";
}
JQuery Call:
$.ajax({
type: "POST",
url: 'frmRequest.aspx/SaveRequest',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
},
failure: function (errMsg) {
alert('failed saving Quotation Request ' + errMsg);
},
error: function (response) {
alert('Error in saving Quotation Request ' + response.d);
}
});
If I use the same code in non-static method its working fine. But its not throwing any execption also.
I need to generate document by using AJAX Call only.
Thanks in advance:-)