Posts

Showing posts with the label C#

POST an array of objects with $.ajax to C# WebMethod

//Create JS method invoking your C# WebMethod (example: getNames)     function getFstNames() {         var myObj = [             { 'fstName': 'name 1', 'lastName':'last name 1', 'age': 32 }           , { 'fstName': 'name 2', 'lastName':'last name 1', 'age': 33 }         ];         var postData = JSON.stringify({ lst: myObj });         console.log(postData);         $.ajax({             type: "POST",             url: "http://yourUrl.aspx/getNames",             data: postData,             contentType: "application/json; charset=utf-8",             dataType: "json",             success: function (response) {   ...

C#/JS/JQuery - download a file with a loading panel

Easy way to use export a document in C # and maintain the loading functionality. First add the functions of add / get cookies https://utilitiesforprogrammers.blogspot.pt/2018/01/jsjquery-cookies.html Second add the loading panel https://utilitiesforprogrammers.blogspot.pt/2018/01/jsjquery-loading.html Now in your event of export add the cookie to track that the process is ended          protected void btnExport(object sender, EventArgs e)         {             try             {                 byte[] bytes = Export();                 this.Page.Response.AppendCookie(new HttpCookie("fileDownloadToken", "1"));                               this.Page.Response.Clear();               ...