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";
}