视图状态值未持久

视图状态值未持久

本文介绍了视图状态值未持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用asp.net网页,其中有三个按钮.我在第一个按钮单击事件中创建视图状态变量(ViewState ["Fid"]).现在在第二个按钮单击事件中,我正在创建新的viewstate变量(ViewState [filename])并分配值.在最后一个按钮事件中,我想使用我无法使用的ViewState变量("Fid"和"filename"). ViewState只有一个变量,即"Fid".尝试访问ViewState ["filename"]时,出现对象引用未设置为实例"错误.我是Web应用程序和状态管理技术的新手.帮助我解决此问题.预先感谢.

Hi ,

I am working with asp.net web page in which I have three buttons. I am creating view state variable(ViewState["Fid"]) in first button click event. Now in second button click event I am creating new viewstate variable (ViewState[filename]) and assigning the value. In last button event I want to use ViewState variables("Fid" and "filename") which I am not able to. ViewState has only one variable i.e., "Fid". I am getting "object reference not set to an instance" error when I am trying to access ViewState["filename"].I am new to web app and state management techniques. Help me in resolving this issue. Thanks in advance.

推荐答案

protected void btnSend_Click(object sender, EventArgs e)
       {
               ViewState["fid"] = "First Value";
      }



第二个按钮单击事件代码



Second Button Click Event Code

protected void btnSend_Click(object sender, EventArgs e)
       {
              ViewState["firstname"] = "Second Value";
       }



第三次Btton Click事件代码和结果显示标签



Third Btton Click Event Code and result am displaying lable

protected void Button2_Click(object sender, EventArgs e)
      {

          lblfinalResult.Text = ViewState["fid"].ToString() + " " +   ViewState["firstname"].ToString();

      }


这篇关于视图状态值未持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:40