1

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.

1

2 Answers 2

3

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.

4
  • 1
    Thank you! so just to clarify, doing this I can have access to my asp:panels from my dashboard.aspx page? Commented Jun 14, 2012 at 14:16
  • If you mean to say that panels are on dashboard.aspx and you want to access them in javascript on dashboard.aspx, i will say yes you can access them. Commented Jun 14, 2012 at 14:21
  • I mean that I want to access them in the imageProcess.aspx code behind, because I need to append html code to them that I generate server-side. Commented Jun 14, 2012 at 14:23
  • You won't be able to access them over in imageProcess.aspx, however from above method you can return the data or html and append that while staying in Dashboard.aspx Commented Jun 14, 2012 at 15:21
0

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

2
  • Well currently I'm calling a different aspx page, but I want to call a function in the current aspx.cs page, but I don't know how to do that. Commented Jun 14, 2012 at 14:06
  • 1
    Well then I think this is what you are looking for: dotnetcurry.com/ShowArticle.aspx?ID=109
    – DerApe
    Commented Jun 14, 2012 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.