I’m making an ajax POST to this url using jQuery like this :
var url = '/Actions/NewBlog.aspx?m=ajax';
$.ajax({
type: 'POST',
url: url,
data: { txt : con },
success: function () {
$('#divDraftMsg').show();
},
dataType: 'text'
});
Then on the server side , I want to read the values of the controls. Here’s my code for that part :
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["m"] != null && !string.IsNullOrEmpty(Request.QueryString["m"]))
{
SaveDraft();
Response.Clear();
return;
}
}
private void SaveDraft()
{
BlogInfo blogInfo = new BlogInfo();
blogInfo.Content_BD = txtContent.Text + hdnDraft.Value;
blogInfo.Owner_ND = Profile.StudentID.ToString();
blogInfo.PostedOn_ND = DateTime.Now;
blogInfo.SaveDraft();
}
But in the code-behind file, the values of all the controls are blank even though they all have values filled up inside the form(UI) before ajax call. So, what’s wrong here???
Also, I’m posting JSON data , but don’t know how to read it from the .cs file???
you need to pass values using
dataand access those as querystring parameters. in this case,Request.QueryString["txt"]