窗口应用程序中viewstate的替代品是什么 [英] what is the replacement for viewstate in window application

查看:109
本文介绍了窗口应用程序中viewstate的替代品是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在asp.net中的代码

This is my code in asp.net

private DataTable CreateDataTable()
   {
       myDataTable = new DataTable("PRODUCTTABLE");

       //DataColumn myDataColumn;

       myDataTable.Columns.Add("Product".ToString());
       myDataTable.Columns.Add("Price".ToString());
       myDataTable.Columns.Add("Quantity".ToString());
       myDataTable.Columns.Add("Total".ToString());
      // myDataTable.Rows.Add(drow);
       ViewState["PRODUCTTABLE"] = myDataTable;
       return myDataTable;
   }





private void Filldatatable()
    {
        myDataTable = (DataTable)ViewState["PRODUCTTABLE"];
        drow = myDataTable.NewRow();
        drow["Product"] = DropDownList1.SelectedItem.Text;
        drow["Price"] = TextBox4.Text;
        drow["Quantity"] = TextBox5.Text;
        drow["Total"] = TextBox6.Text;
        myDataTable.Rows.Add(drow);
        GridView1.DataSource = myDataTable;
        GridView1.DataBind();


    }


现在我想在窗口应用程序中编写相同的代码
但在那里我找不到viewstate.so如何在窗口中做到这一点.
我现在该怎么办.请帮助


now i want to write the same code in window application
but there i am not finding viewstate.so how can i do so.. in window.
what should i do now .please help

推荐答案

您需要阅读有关Winform应用程序开发基础的知识.

或者至少,应该基于您的ASP.NET知识来了解/注意两者之间的区别.如果知道的话,在ASP.NET中就有回发客户端-服务器请求-响应……的概念,以及各种状态管理技术.

Viewstate是一种状态管理技术,可在回发之间持久保存页面的值.现在,Winforms中没有回发的概念.因此,不需要Viewstate之类的东西.

您怎么说,我对您有帮助的方向了吗?
You need to read-learn on the basics of Winform application development.

Or atleast, should understand/notice the difference between the two based on your ASP.NET knowledge. If you know, in ASP.NET there is this concept of postback, client-server request-response thing... and thus various state management techniques.

Viewstate is one of the state management technique to persist the values for the page across postbacks. Now, there is no concept of postbacks in Winforms. Thus, no need of anything like Viewstate.

What do you say, did I put you on some direction that looks helpful?


桌面应用程序没有这样的概念. ASP.NET中的视图状态是与 HTTP协议是无状态的有关;而这需要解决富Web应用程序的问题.桌面应用程序永久支持所有状态是显而易见的原因,因此这种概念不适用.

但是,在桌面应用程序的体系结构级别上,问题在于保持UI状态与数据之间的一致性(大致而言).有许多建筑设计模式( http://en.wikipedia.org/wiki/Architectural_pattern [ ^ ]),这有助于支持状态一致性(尤其是):MVVM( http://en.wikipedia.org/wiki/MVVM [ http://en.wikipedia.org/wiki/Model_View_Controller [ ^ ])及其派生的Model-view-presenter( http://en.wikipedia.org /wiki/Model-view-presenter [ ^ ]).

MVVM也许是.NET最受欢迎的架构模式.

要在MVVM上获得一个不错的主意,请看以下示例:
解释了Model-View-ViewModel(MVVM) [ WPF:简化MVVM(模型视图视图模型) [ WPF第II部分中的MVVM [
There is no such concept for desktop application. View state in ASP.NET is related to the fact that HTTP protocol is stateless; and that needs working around for rich Web application. A desktop a application support all states permanently be the obvious reasons, so such concept is not applicable.

Nevertheless, at the architectural level of the desktop application the problem is maintaining coherency between UI states and the data (roughly speaking). There is a number of architectural design patterns (http://en.wikipedia.org/wiki/Architectural_pattern[^]) which help to support the state coherence (in particular): MVVM (http://en.wikipedia.org/wiki/MVVM[^]), Model-View-Controller (http://en.wikipedia.org/wiki/Model_View_Controller[^]) and its derivative Model-view-presenter (http://en.wikipedia.org/wiki/Model-view-presenter[^]).

Perhaps MVVM is the most popular architectural pattern for .NET.

To get a pretty good idea on MVVM, look, for example, here:
Model-View-ViewModel (MVVM) Explained[^],
WPF: MVVM (Model View View-Model) Simplified[^],
MVVM in WPF Part II[^].

Seach CodeProject for more information: there is a lot of interesting articles.

—SA


这篇关于窗口应用程序中viewstate的替代品是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆