Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:值未在回发中持久化_C#_Variables - Fatal编程技术网

C#:值未在回发中持久化

C#:值未在回发中持久化,c#,variables,C#,Variables,在该代码中,复选框的单个值是确定的,但当总数为0时,它变为0 请帮助我修复它。回发不会持久化“结果”值。您可以在需要最终结果时始终重新计算它,或者将其存储在viewstate中。回发时不会保留“结果”值。当您需要最终结果时,请始终重新计算它,或者将其存储在viewstate中。结果变量不会在数字回发中保留,因为web应用程序的性质是无状态的,所以请将结果存储在viewstate或Session变量中,如下所示 using System; using System.Collections; usi

在该代码中,复选框的单个值是确定的,但当总数为0时,它变为0


请帮助我修复它。

回发不会持久化“结果”值。您可以在需要最终结果时始终重新计算它,或者将其存储在viewstate中。

回发时不会保留“结果”值。当您需要最终结果时,请始终重新计算它,或者将其存储在viewstate中。

结果变量不会在数字回发中保留,因为web应用程序的性质是无状态的,所以请将结果存储在viewstate或Session变量中,如下所示

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class expt2 : System.Web.UI.Page
{
    double result ;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            result = 0.0;
 protected void Chkbxbd_CheckedChanged(object sender, EventArgs e)
    {
        if (Chkbxbd.Checked)
        {
            txtbxttl.Text = "" + 10000;
            result += double.Parse(txtbxttl.Text);

        }
        else
            result = result - 10000;


      }
    protected void Chkbxsfa_CheckedChanged(object sender, EventArgs e)
    {
        if (Chkbxsfa.Checked)
        {
            txtbxttl.Text = "" + 15000;
            result += double.Parse(txtbxttl.Text);

        }
        else
            result = result - 15000;


    }
 protected void btnttl_Click(object sender, EventArgs e)
    {
        txtbxttl.Text = "" + result;

    }
}

结果变量不会在数字回发中保留,因为web应用程序的性质是无状态的,所以将结果存储在ViewState或Session变量中,如下所示

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class expt2 : System.Web.UI.Page
{
    double result ;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            result = 0.0;
 protected void Chkbxbd_CheckedChanged(object sender, EventArgs e)
    {
        if (Chkbxbd.Checked)
        {
            txtbxttl.Text = "" + 10000;
            result += double.Parse(txtbxttl.Text);

        }
        else
            result = result - 10000;


      }
    protected void Chkbxsfa_CheckedChanged(object sender, EventArgs e)
    {
        if (Chkbxsfa.Checked)
        {
            txtbxttl.Text = "" + 15000;
            result += double.Parse(txtbxttl.Text);

        }
        else
            result = result - 15000;


    }
 protected void btnttl_Click(object sender, EventArgs e)
    {
        txtbxttl.Text = "" + result;

    }
}

请问一个实际的问题。解释正在发生的事情和你期望发生的事情。请问一个实际的问题。解释正在发生的事情以及您期望发生的事情。但是,每当回发发生时,result的值如何变为0.0,因为只有在没有回发的情况下,它才能获得值所有数字类型的默认值为零。在每次回发中,它都以零开始。但是,每当回发发生时,result的值如何变为0.0,因为只有在没有回发时,它才能获得值所有数字类型的默认值均为零。在每次回发中,它都以零开头。感谢朋友的回复。但是,无论何时回发,result的值是如何变为0.0的,因为只有在没有回发的情况下才能获得值谢谢朋友的回复。但是,无论何时发生回发,result的值如何变为0.0,因为它只能在没有回发的情况下获取值