Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Refer this link

http://www.aspsnippets.com/Articles/Calling-server-side-function-from-JavaScript-in-ASP.Net.aspx[^]

Here direct method is called instead of entire page lifecycle n i want in same way
It all works fine but how about non static method
Is there any way by javascript or jquery

Please suggest
Posted
Updated 28-Dec-11 1:45am
v3
Comments
Wendelius 28-Dec-11 7:45am    
Link formatted
Amir Mahfoozi 28-Dec-11 7:54am    
+5 for interesting link.
Rakesh S S 28-Dec-11 7:58am    
thanks

Make a static method as the article mentioned and create an instance of your desired class and use its functions and return the results to the client side.
For example :
C#
public static string GetCurrentTime(string name)
{
   ClassToBeUsed c = new ClassToBeUsed();
   return c.NonStaticMethod(); 
}


Hope it helps.
 
Share this answer
 
Hi Please use following:

Server side
C#
[System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static object GetUploadStatus()
    {
        //Get the length of the file on disk and divide that by the length of the stream
        UploadDetail info = (UploadDetail)HttpContext.Current.Session["UploadDetail"];
        if (info != null && info.IsReady)
        {
            int soFar = info.UploadedLength;
            int total = info.ContentLength;
            int percentComplete = (int)Math.Ceiling((double)soFar / (double)total * 100);
            string message = "Uploading...";
            string fileName = string.Format("{0}", info.FileName);
            string downloadBytes = string.Format("{0} of {1} Bytes", soFar, total);
            return new
            {
                percentComplete = percentComplete,
                message = message,
                fileName = fileName,
                downloadBytes = downloadBytes
            };
        }
        //Not ready yet
        return null;
    }


Client side
JavaScript
PageMethods.GetUploadStatus(function(result) {
            if (result) {
                setProgress(result.percentComplete);
                //Upadte the message every 500 milisecond
                updateMessage(MessageStatus.Information, result.message, result.fileName, result.downloadBytes);
                if (result == 100) {
                    //clear the interval
                    window.clearInterval(intervalID);
                    clearTimeout(subintervalID);
                }
            }
        });


You can find more help here....
ASP.NET File Upload with Progress Bar[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900