如何在没有回发的情况下从服务器调用非静态方法? [英] How to call Non-static method from server without postback?
本文介绍了如何在没有回发的情况下从服务器调用非静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请参阅此链接
http://www.aspsnippets.com/Articles/从ASP.Net.aspx中的JavaScript调用服务器端功能- [
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
推荐答案
尝试
使用Ajax.NET Framework通过JavaScript调用服务器端代码 [ http://sunilgurjar.blogspot.com/2011/03/implementing-icallbackeventhandler-in.html [^ ]
Try
Call Server Side Code by JavaScript using Ajax.NET Framework[^]
http://sunilgurjar.blogspot.com/2011/03/implementing-icallbackeventhandler-in.html[^]
使静态方法如本文所述,并创建所需类的实例,并使用其功能并将结果返回给客户端.
例如:
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 :
public static string GetCurrentTime(string name)
{
ClassToBeUsed c = new ClassToBeUsed();
return c.NonStaticMethod();
}
希望对您有所帮助.
Hope it helps.
请使用以下内容:
服务器端
Hi Please use following:
Server side
[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
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);
}
}
});
您可以在此处找到更多帮助....
带有进度条的ASP.NET文件上传 [
You can find more help here....
ASP.NET File Upload with Progress Bar[^]
这篇关于如何在没有回发的情况下从服务器调用非静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文