Reputation: 3609
So I have something like this situation:
$(document).on('click', 'a[data-link]', function () {
var $this = $(this);
url = $this.data('link');
$("#imagePreview").load("imageProcess.aspx?" + url);
where url holds GET
parameters. But imageProcess.aspx
is different than the file I'm in (dashboard.aspx
) and I need to reference some panels within my dashboard.aspx
file. So my question is, using the .load() function, or even any function that could get the job done, how do I call a function, with GET
parameters, in the dashboard.aspx
code behind file? I'm fairly new to the .NET
framework so I apologize if the question sounds elementary.
Upvotes: 1
Views: 2510
Reputation: 2170
In your imageProcess.aspx.cs
create a webmethod like:
[WebMethod]
public static string YourMethod(your parameters)
{
//Do Your Work
}
and in your dashboard page, in javascript use jquery to send request your webmethod like:
$.ajax({
type: "POST",
url: "imageProcess.aspx/YourMethod",
data: "{parameter1Name:'" + JSON.stringify(parameter1value) + "', Parameter2Name:'" + JSON.stringify(parmeter2Value) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// do your success work, keep in mind that your returned data will be in data.d
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
// do your failuer work
}
});
I hope it will give you a guidance to achieve your task.
Upvotes: 3
Reputation: 3175
Just to make sure: You are trying to access functionality from a different aspx page than the one you are currently on. I'm not entirely sure if you can do that the easy way by java script. Maybe someone else knows a better way, but the way I would do it is creating ashx service page which will handle your request so you can provide the data you need (in your case an image)
For more information see http://www.dotnetperls.com/ashx
Upvotes: 0