从代码返回值到 asp.net ajax endrequest
基本上,我有一个启用了 asp.net ajax 的用户控件,现在我只想返回一个简单的字符串值,以便在 ajax 请求完成后在我触发的一些 js 中使用。
我一直在摆弄 endrequest 方法,我已经设置该方法用于异常处理,效果很好。但是有没有办法简单地返回一个字符串值呢?
首先我想我可以通过 Response.Write(); 来做到这一点但 args.get_response() 不喜欢你这样做 - 谁能指出我正确的方向?
谢谢!
Basically, I have an asp.net ajax enabled usercontrol, and now I'd like to just return a simple string value, to be used in some js I'm firing after the ajax request is done.
I've been fiddling around with the endrequest method, which I already set up to use for exception handling, which works fine. But is there no way to simply return a string value?
First I thought I could do this through Response.Write(); but args.get_response() doesn't like when you do that apparantly - can anyone point me in the right direction?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 ScriptManager.RegisterDataItem 方法与 Sys.WebForms.PageRequestManager 结合使用。考虑以下测试页面,当您单击按钮时,它会向脚本管理器注册数据项,并在客户端处理最终请求并获取该数据项,
You can use the ScriptManager.RegisterDataItem method with the Sys.WebForms.PageRequestManager. Consider the following test page which when you click the button it registers data item with the script manager and at the client side it handles the endrequest and get that data item,
也许我不明白你的问题,但是用户控件与额外的 js 调用有什么关系?您只是从用户控件渲染该 js 吗?
无论如何,IMO 您应该使用 ASP.NET Web Handler (*.ashx) 或 HttpHandler 返回字符串值并使用该附加 js 调用该处理程序。
Maybe I don't understand your problem, but what usercontrol had to do with that additional js calls ? You are just rendering that js from user control ?
Anyway, IMO You should use ASP.NET Web Handler (*.ashx) or HttpHandler to return string value and call that handler with that additional js.