问题描述
我不认为这是可能的,但我只是和一位同事交谈,她说她以前做过.她在拉我的链子吗?
I didn't think it was possible but I was just talking to a co-worker who said she had done it before. Is she pulling my chain?
推荐答案
这不是您可以自动完成的.
It's not something you can do automatically.
诀窍是 Winforms 和 Webforms 都使用普通的旧类表示表单.然而,与 Winforms 相比,Webforms 中类的实例是短暂的;每个 Webforms 类实例仅代表一个 HTTP 请求,而不是与 Winforms 一样的表单的整个生命周期.每次在 ASP.Net Webforms 中为表单处理事件时,您都在使用该类的一个全新实例.Microsoft 费尽心思尽可能地解决这个问题,但最终将 Webform 视为与 Winform 相同的术语并不是一个好主意.
The trick is both Winforms and Webforms represent a form using a plain old class. However, instances of the class in Webforms are short-lived compared to Winforms; each Webforms class instance represents only one HTTP request, rather than the entire lifetime of the form, as with Winforms. Every time you handle an event for your form in ASP.Net Webforms you're working with a brand new instance of the class. Microsoft went to a lot of trouble to try cover for this issue as much as possible, but in the end it's just not a good idea to think of a Webform in the same terms as a Winform.
您绝对可以使用 Winforms 应用程序并重写它以使用 Webforms,但这只是:重写.
You can definitely take a Winforms app and rewrite it to use Webforms, but it will be just that: a rewrite.
这篇关于是否可以在 .NET 中将 WinForm 转换为 WebForm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!