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('item.Date');
});
}).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);