We have a Sharepoint solution that uses AJAX. The button that triggers this is inside an update panel.
One of the things that we do is generate a MS Word document, t
I've struggled with this for a few hours. Doing an ajax request within my WebForms Code-Behind
file wasn't working & using an UpdatePanel
resulted in that annoying error and I wasn't able to find a solution. Finally I found a solution that works!
.ashx
(Generic Handler) file. I created mine within a top level services folder so: Services\EventsHandler.ashx
. When you do this you should end up with both an .ashx
& .ashx.cs
file.ashx.cs
file you'll find a ProcessRequest
method where you can put all of your code.You can call this method doing something similar to the following in your javascript file:
$('#MyButton').click(function () {
var zipCode = $('#FBZipBox').val();
$.getJSON('/Services/EventsHandler.ashx?zip=' + zipCode, function (data) {
var items = [];
$.each(data.Results, function (key, item) {
items.push('<span>item.Date</span>');
});
}).complete(function () {
// More Logic
});
return false;});
Within your ashx.cs
file you can access the query parameters using:
var category = context.Request.QueryString["zipCode"];
You can then return the result using:
context.Response.Write(yourResponseString);
If you have the button inside updatepanel this maybe causing this, if don´t want to move it, just add a trigger for the button on the updatepanel, a postback trigger.
Try adding script manager in your page load, like this:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnExport);
For me the problem was duplicate control ID's in template columns of a grid view. Once I renamed the controls to be unique grid-wide, the problem disappeared!
I had an asp:Table control inside an asp:UpdatePanel control. The table had some static rows and some rows were added during a Postback event.
This error occurred because rows and columns of the table did not have static IDs. So IDs changed at each postback and this cause problems with restoring ViewState for the table.
To stop this error I disabled ViewState for the table: EnableViewState="false"
<asp:Table ID="PageContentTable" runat="server" ... EnableViewState="false">
I removed the update panel around the button and it worked fine.