开发者

Alternatives to UpdatePanel on a user control (ASCX page)

I am currently working on a ASP.NET AJAX application. Having decided to not use UpdatePanels for evident reasons, what alternatives to I have? This application has pages built dynamica开发者_Go百科lly and so most or all the components of the page exist as User Controls.

I need to make AJAX calls from ASCX user control page. And as ASCX user controls may not contain Page Methods, what other options do I have?

Or, is there a way to get around using Page Methods in ASCX page?


You can't call webmethods from a UserControl as you said. The reason for this is methods marked with the WebMethod attribute must also be static. UserControls don't support this. If you aren't willing to use an UpdatePanel, you don't have a lot of options.

You could make AJAX calls via jQuery to web services? This would be one option...

UpdatePanel controls used with UpdateMode="Conditional" gives you fairly good control over what is happening with the callbacks and is still a reasonable solution. It won't be as lightweight as a straight ajax call but will be easy to maintain, etc.


jQuery AJAX is my recommendation, used with web services provides a nice solution.


Best way (that I discovered) is to 1. Place your PageMethods on the parent page 2. When the PageMethod completes, let your user control know via a JS method that it can the PageMethod call has been completed 3. Then a ICallbackHandler can be implemented on the user control to do a AJAX callback on the user control's method

In my case, I need to update some values on the user control after the PageMethods gets executed, so I build my user control using HtmlOutputWriter to update the contents.

Works for me!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜