想用.NET带的ScriptManager实现AJAX,不使用UpdatePanel。
页面实现了ICallBackEventHandler,对需要处理的事件进行处理。
但导致了一个问题,就是GetCallbackResul成员变得责任重大,紧耦合,低内聚。问一下,大家都是怎么做的?
页面实现了ICallBackEventHandler,对需要处理的事件进行处理。
但导致了一个问题,就是GetCallbackResul成员变得责任重大,紧耦合,低内聚。问一下,大家都是怎么做的?
解决方案 »
- 纠结的实体类
- 可不可一般jquey这个看成一个申明对象,这个应该是js独有的吧,比较感觉很陌生
- 为什么在C#下设置弹出窗口 弹出的窗口不走Load时间
- 怎么实现网页标题的动态变化
- 谁能个介绍份ASP.NET程序员的工作呀?
- 无法读取linq的问题
- asp.net复制共享文件
- 大家先不要说我变态,先帮忙解决问题是关键.
- 不知道大家现在的收入都怎么样,工作满意不?(非技术问题,纯属闲聊)
- 用户 '**' 登录失败。原因: 未与信任 SQL Server 连接相关联
- 刷新父页面的问题,虽然很多人问了,但还是要问,这个不一样!
- try---catch--finally 的疑问?(问题在finally那里)
Calling Web Services from Client Script in ASP.NET AJAX
Calling Web Service Methods
// CallWebServiceMethods.js
// This function calls the Web service method without
// passing the callback function.
function GetNoReturn()
{
Samples.AspNet.WebService.GetServerTime();
alert("This method does not return a value.");
}
// This function calls the Web service method and
// passes the event callback function.
function GetTime()
{
Samples.AspNet.WebService.GetServerTime(
OnSucceeded);
}
// This function calls the Web service method
// passing simple type parameters and the
// callback function
function Add(a, b)
{
Samples.AspNet.WebService.Add(a, b,
OnSucceeded);
}// This function calls the Web service method
// that returns an XmlDocument type.
function GetXmlDocument()
{
Samples.AspNet.WebService.GetXmlDocument(
OnSucceededWithContext, OnFailed,
"XmlDocument")
}// This function calls a Web service method that uses
// GET to make the Web request.
function MakeGetRequest()
{ Samples.AspNet.WebService.EchoStringAndDate(
new Date("1/1/2007"), " Happy",
OnSucceeded,
OnFailed, "HappyNewYear");}// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the
// calling method name as parameters.
function OnSucceededWithContext(result, userContext, methodName)
{
var output;
// Page element to display feedback.
var RsltElem = document.getElementById("ResultId");
var readResult;
if (userContext == "XmlDocument")
{
if (document.all)
readResult =
result.documentElement.firstChild.text;
else
// Firefox
readResult =
result.documentElement.firstChild.textContent;
RsltElem.innerHTML = "XmlDocument content: " + readResult;
}
}// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function OnSucceeded(result, eventArgs)
{
// Page element to display feedback.
var RsltElem = document.getElementById("ResultId");
RsltElem.innerHTML = result;
}
// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function OnFailed(error)
{
// Display the error.
var RsltElem =
document.getElementById("ResultId");
RsltElem.innerHTML =
"Service Error: " + error.get_message();
}if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
当然,你可以使用自己封装的AJAX组件,这样就解决了这个问题。另外AJAXPRO提供的访问手段是通过HTTPMODULE做的,很方便,解决了LZ的问题,但大量的反射消耗更多的资源,未必是可取的。同样,直接请求一个URL对于一个页面来说,也是紧耦合,低内聚。所以,应该用UppdatePanel。