0

I have an issue that if the user types and formats the text the information is sucessfully submitted. However, if the user copies and pastes formatted text (i.e. Word Document Text) it fails to submit. I get a 500:Internal Server Error. Which does not make sense since the script works when I type in information. It only fails when I copy something and paste it in the div.

I tried using this solution by Erik Woods https://jsfiddle.net/erikwoods/Ee3yC/ However I am using IE11 and insert text is not supported with that version.

    $(document).ready(function () {
        $('#btnsubmit').click(function () {
                $.ajax({  
                type: 'POST',  
                contentType: "application/json; charset=utf-8",  
                    url: 'Test.aspx/Insert',
                    data: "{'SubjectDiv':'" + document.getElementById('SubjectDiv').innerHTML + "','PurposeDiv':'" + document.getElementById('PurposeDiv').innerHTML + "'}",  
                async: false,  
                success: function(response)
                {
                    alert("Success!")
                },  
                error: function(xhr, status, error) 
                {
                  var errorMessage = xhr.status + ': ' + xhr.statusText
                  alert('Error - ' + errorMessage);   
                }  
            }); 
    });
});

        [WebMethod]
        public static string Insert(string SubjectDiv, string PurposeDiv)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
            var NetworkID = HttpContext.Current.User.Identity.Name;
            string username = NetworkID.Substring(4);

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlCommand comm = new SqlCommand("INSERT INTO Data (Subject, Purpose) Values (@Subject, @Purpose)", conn);
                comm.CommandType = CommandType.Text;

                comm.Parameters.AddWithValue("@Subject", SubjectDiv);
                 comm.Parameters.AddWithValue("@Purpose", PurposeDiv);
                conn.Open();
                comm.ExecuteNonQuery();
                conn.Close();
            }
            return "True";
        }
Dan Nick
  • 514
  • 1
  • 9
  • 30
  • What error message it gives when you save the data? – Golda May 15 '19 at 05:23
  • @Golda I updated the question. But I get a 500:Internal Server Error. Which does not make sense because it only fails when I paste data into the div. – Dan Nick May 15 '19 at 13:35
  • 1
    You can check the exact error message in the inspect element. I hope this answer will help you. Check the link https://stackoverflow.com/a/30023642/2501044 – Golda May 15 '19 at 13:53
  • @Golda Thank you. That link helped a lot. – Dan Nick May 16 '19 at 14:47

0 Answers0