简体   繁体   English

如何将控件异步添加到asp.net页?

[英]How can I asynchronously add controls to a asp.net page?

I'm looking to optimize pages within our application so they perform better. 我希望在我们的应用程序中优化页面,以使其表现更好。 I want to dynamically add controls (Textbox, Button, Custom Control, etc) to a page using AJAX to minimize postbacks done. 我想使用AJAX将控件(文本框,按钮,自定义控件等)动态添加到页面,以最大程度地减少回发。 I'm looking for an alternative to using an UpdatePanel (nothing wrong with them, they're just not built for performance). 我正在寻找使用UpdatePanel的替代方法(它们没什么问题,它们不是为提高性能而构建的)。

The trick though is that the ViewState will need to be updated with the new controls added, so I can't see WebServices or static Page Method calls fitting in well here. 但是,窍门在于,将需要使用添加的新控件来更新ViewState,因此在这里我看不到适合的WebServices或静态Page Method调用。

Ajax calls cannot update viewstate as that is created in code behind. Ajax调用无法更新viewstate,因为它是在后面的代码中创建的。

Maybe if you manage to access the viewstate server side you could send it back in the ajax call and store it in the viewstate field but you risk loosing anything that was not touched in the callback, I have never delved that deep into viewstate. 也许如果您设法访问viewstate服务器端,可以将其发送回ajax调用中并存储在viewstate字段中,但是您可能会失去未在回调中触及的所有内容,我从没有深入研究viewstate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM