ASP.NET - PageMethods.GetImageDimension is not a function

Asked By Daniel on 03-Oct-12 11:12 AM
I am new to ajax and JQuery.And I am facing this isseus when uploading a picture:
PageMethods.GetImageDimension is not a function

I am using this code in Code behind file,to implement the function:

[WebMethod(EnableSession = true)]
    public static string GetImageDimension()
    {
        return HttpContext.Current.Session["ImageDimension"].ToString();
    }
And this is in html with JQuery:

 function uploadComplete(sender, args) {
        filename = args.get_fileName(); 
        PageMethods.GetImageDimension(function (response) {
            $dimension = eval(response); 
            $width = $dimension.width;
            $height = $dimension.height;
            showlightbox();
        });
    }
Robbe Morris replied to Daniel on 03-Oct-12 12:06 PM
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Daniel replied to Robbe Morris on 03-Oct-12 12:48 PM
Hi Robbes!I think I done it correctly but I have a little question,like
this code is inside  a usercontol file
 function uploadComplete(sender, args) {
        filename = args.get_fileName(); //it gets file name to be uploaded(toolkit functions)
        PageMethods.GetImageDimension(function (response) {
            $dimension = eval(response); //response is in json format
            $width = $dimension.width;
            $height = $dimension.height;
            showlightbox();
        });
    }
and this code is inside a c# code behind file:
[WebMethod(EnableSession = true)]
    public static string GetImageDimension()
    {
        return HttpContext.Current.Session["ImageDimension"].ToString();
    }
  Then My question is I am need a generic handler to perform that ?
if yes how can I access this function inside a class that that I called member using generic handler.

public MemberInfo(int Id)
     {
        SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.GetConnection(), "GetUserByUserId", Id);
        if (dr.HasRows)
        {
            dr.Read();
            UserId = Convert.ToInt32(dr["UserId"]);
            Name = Convert.ToString(dr["Name"]);
            Image = Convert.ToString(dr["Image"]);
            CompanyName = Convert.ToString(dr["CompanyName"]);
            Description = Convert.ToString(dr["Description"]);
            Experience = Convert.ToString(dr["Experience"]);
            Address = Convert.ToString(dr["Address"]);
            Website = Convert.ToString(dr["Website"]);
            RegistrationType = Convert.ToInt32(dr["RegistrationType"]);
            PhoneNo = Convert.ToString(dr["PhoneNo"]);
            UserName = Convert.ToString(dr["UserName"]);
            Password = Convert.ToString(dr["Password"]);
            UserTypeId = Convert.ToInt32(dr["UserTypeId"]);
        }
    }
Robbe Morris replied to Daniel on 03-Oct-12 01:18 PM
You cannot put your page methods in an ASP.NET UserControl.  You'll have to put your WebMethod in the code behind of the containing asp.net page.  Kinda sucks but there is no way to identify the path of the method if it is in a user control.


Daniel replied to Robbe Morris on 03-Oct-12 01:42 PM
Thanks!