Possible to load ASCX with jQuery.load() function?

风格不统一 提交于 2019-12-11 19:14:35

问题


Is it possible without encapsulating these controls in aspx files? The Register tag makes me think that it is not.


回答1:


You can't call ascx page directly, they can't serve any html without added to aspx or render then dynamically in response to any page/handler.




回答2:


One possible way would be to have a generic aspx stub page that acts as a host to the ascx in the normal web forms way make a callback to the that page using JQuery's $.ajax() method with some arguments to denote what ascx control you want to load.

Then on your stub / host page, override the render method and render the control directly to the output stream using response.output.write. The callback handler on the client will catch the output and then it can be inserted into the DOM in the normal way or using using the version of $.load() that allows the specification of a DOM element.

hope this helps.




回答3:


This is one way to load ASCX controls through jQuery, using an ASMX service that creates a Page instance to render the user control.




回答4:


Since I've started using jQuery/Ajax more and more, I find I've been using server controls less and less.

Things that I used to put into controls are now just individual aspx pages which get loaded into panels.

If you have old ASCX files, it shouldn't be too hard to convert them to ASPX




回答5:


No.

That said, you could place your ascx inside an UpdatePanel and set the panel's content visible/invisible using the standard Asp.Net postback mechanisms.

Or you could write a separate IHttpHandler which generates HTML code that your Javascript code adds to the page using DOM. This part of the page would however not be accessible in PostBack.




回答6:


No, ASCX are user-controls, that exist on ASPX. You will need to make it a Page, or convert into Handler.



来源:https://stackoverflow.com/questions/1212639/possible-to-load-ascx-with-jquery-load-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!