Showing posts with label ajax. Show all posts
Showing posts with label ajax. Show all posts

Wednesday, October 28, 2015

Json pass object to webmethod using c#

javascript function:

function Archive_insert_Save_DB(saved_Doc_Extension) {
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    var datajsonparam = {
        hidLibrary: $('#hidLibrary').prop('value'),
        hidFormID: $("#hidFormID").prop('value'),
        hidProfileID: "" + $("#hidProfileID").prop('value'),
        hidDocID: $("#hidDocID").prop('value'),
        hidDocName: $("#hidDocName").prop('value'),
        hidIsVersion: $("#hidIsVersion").prop('value'),
        hidDocComment: $("#hidDocComment").prop('value'),
        hidFTPGuidName: $("#hidFTPGuidName").prop('value'),
        hidUserID: $("#hidUserID").prop('value'),
        HidMRTYPE: $("#HidMRTYPE").prop('value'),
        hidDOC_DATE_EN: $("#hidDOC_DATE_EN").prop('value'),
        hidDOC_DATE_AR: $("#hidDOC_DATE_AR").prop('value'),
        saved_Doc_Extension: saved_Doc_Extension

    };
    $.ajax({
        type: "POST",
        url: "scan.aspx/Add_Document_DB_Operations",
        data: JSON.stringify({ DocumentDetails: datajsonparam }),
        //'{"hidLibrary" : "' + $("#hidFTPServer").prop('value') + '" ,"lang" : "' + lang + "hidLibrary" : "' + $("#hidFTPServer").prop('value')   }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            $("#hidDocID").val(result.d);
            alert("تمت عملية الأرشفة بنجاح - Archive Operation Succeeded");
            window.opener.location.reload();
            window.close();
        },
        error: function (x, e) { alert(x.responseText); }
    });
}
--------------------------------------------------------------------
   [WebMethod]
        public static string  Add_Document_DB_Operations(DocumentDetail DocumentDetails)
        {
                if (DocumentDetails.hidIsVersion.Length > 0)
                {
                    //insert document in table doc_Versions
                    string doc_version_ID = archive_Class.Doc_Versions_INSERT(DocumentDetails.hidDocID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);
                    //update main version to the new version inserted
                    archive_Class.Doc_Versions_Set_AS_Main_Doc(int.Parse(DocumentDetails.hidDocID), int.Parse(doc_version_ID));
                    //update main document in table profile_docs to the name of the new version file
                    archive_Class.Profile_Docs_UPDATE_Phisical_File_Name(int.Parse(DocumentDetails.hidDocID), DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);

                    try
                    {
                        archive_Class.Archive_History_Insert(int.Parse(DocumentDetails.hidLibrary), int.Parse(DocumentDetails.hidFormID), int.Parse(DocumentDetails.hidProfileID), int.Parse(DocumentDetails.hidDocID), int.Parse(doc_version_ID),
                        Convert.ToInt32(ArchiveOperations.DocVersion_Add),
                        Convert.ToInt32(DocumentDetails.hidUserID), "  تم عمل مسح ضوئي لوثيقة الإصدار رقم  :  " + doc_version_ID.ToString() + "  عنوان الوثيقة   : " + DocumentDetails.hidDocName);

                    }
                    catch (Exception ex)
                    { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); }

                }
                else
                {
                    if (DocumentDetails.HidMRTYPE.Length > 0)

                        DocumentDetails.hidDocID = archive_Class.Profile_Docs_INSERT_MR(DocumentDetails.hidProfileID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID, DocumentDetails.HidMRTYPE, DocumentDetails.hidDOC_DATE_EN, DocumentDetails.hidDOC_DATE_AR);
                    else
                        //insert documents in db in table profile_Docs
                        DocumentDetails.hidDocID = archive_Class.Profile_Docs_INSERT(DocumentDetails.hidProfileID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);

                    //insert new version for the document and make it as main doc version
                    archive_Class.Doc_Versions_INSERT(DocumentDetails.hidDocID, DocumentDetails.hidDocName, DocumentDetails.hidDocComment, DocumentDetails.hidFTPGuidName + DocumentDetails.saved_Doc_Extension, DocumentDetails.hidUserID);

                    //try
                    //{
                        archive_Class.Archive_History_Insert(int.Parse(DocumentDetails.hidLibrary), int.Parse(DocumentDetails.hidFormID), int.Parse(DocumentDetails.hidProfileID), int.Parse(DocumentDetails.hidDocID), 0,
                        Convert.ToInt32(ArchiveOperations.Document_Add),
                        Convert.ToInt32(DocumentDetails.hidUserID), "  تم عمل مسح ضوئي للوثيقة رقم  :  " + DocumentDetails.hidDocID + "  عنوان الوثيقة   : " + DocumentDetails.hidDocName);

                    //}
                    //catch (Exception ex)
                    //{ Elmah.ErrorSignal.FromCurrentContext().Raise(ex); }

                }
                // _ArchiveClass.CreateArchiveFolders(DocumentDetails.hidLibrary, DocumentDetails.hidFormID, DocumentDetails.hidProfileID, DocumentDetails.hidDocID);
                //ftp "/" + hidLibraryID.Value + "/" + hidFormID.Value + "/" + hidProfileID.Value + "/" + row.Cells[0].Text + "/" + phisicalname);

                Doc_Server doc_srv = new Doc_Server(int.Parse(DocumentDetails.hidDocID.ToString()));
            string controlSavedPath="/" + DocumentDetails.hidLibrary + "/" + DocumentDetails.hidFormID + "/" + DocumentDetails.hidProfileID + "/" + DocumentDetails.hidFTPGuidName + ".pdf";
                doc_srv.ftpRelativeFilePath = "/" + DocumentDetails.hidLibrary + "/" + DocumentDetails.hidFormID + "/" + DocumentDetails.hidProfileID + "/" + DocumentDetails.hidDocID + "/";
                FTP_Handler.CreateFTP_Directories(doc_srv);
                FTP_Handler.ftp_Move_File_afterSave(doc_srv, controlSavedPath, doc_srv.ftpRelativeFilePath, DocumentDetails.hidFTPGuidName + ".pdf");

            //}
            //catch (Exception ex)
            //{
            //    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            //    var message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
            //    string script = "alert('" + ex.Message + "');";
            //    Page.ClientScript.RegisterStartupScript(this.GetType(), "sctipKey", script, true);
             
            //}

            return DocumentDetails.hidDocID;
         
        }
     
    }
---------------------------------------------------------------------------
Class

    public class DocumentDetail
    {
        public string hidLibrary { get; set; }
        public string hidFormID { get; set; }
        public string hidProfileID { get; set; }
        public string hidDocID { get; set; }
        public string hidDocName { get; set; }
        public string hidIsVersion { get; set; }
        public string hidDocComment { get; set; }
        public string hidFTPGuidName { get; set; }
        public string hidUserID { get; set; }
        public string HidMRTYPE { get; set; }
        public string hidDOC_DATE_EN { get; set; }
        public string hidDOC_DATE_AR { get; set; }
        public string hidVersionID { get; set; }
        public string saved_Doc_Extension { get; set; }
    }
}

Tuesday, December 24, 2013

System.Web.HttpException : This is an invalid webresource request Clear Cach



this error solution according to post http://forums.asp.net/t/1609380.aspx
is to clear cach for your page request so the following code clear cach in client side just call the function in page load to solve the webresource.axd prbolem when change your application host from framework version to another or any updates affects on cached data on client side .


using meta Tag
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
 
Using Server side function
Public Shared Sub ClearCachForPage()
        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
        HttpContext.Current.Response.Cache.SetValidUntilExpires(False)
        HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache)
        HttpContext.Current.Response.Cache.SetNoStore()

    End Sub