Post back如何重置?

时间:2014-05-27 20:29:58

标签: c#

让我详细说明一下......我有下面的代码,有一个Page_Init(我仍然不理解为什么它不止一次,但那是另一个故事),还有一个Page_Load和我我正在检查" isPostBack" ...当我使用我的控件,单选按钮和下拉列表以及按钮时,一切都很好用;但是,如果我按下按键,即使是偶然的,也就是说,#is; isPostBack"重置为False。我究竟做错了什么?另外,我的AutoEventWireup =" true"。 此外,这是一个.ascx文件。

protected void Page_init(object sender,EventArgs e)     {

        LoadPageText1();

        paymntpnl1.Visible = true;
        curbalpnl.Visible = false;
        paymntpnl2.Visible = false;
        paymntpnl3.Visible = false;
        paymntpnlcc.Visible = false;

}



protected void Page_Load(object sender, EventArgs e)
{


    LoadPageData();
    getContractInfo();
    step2lbl.BackColor = System.Drawing.Color.White;
    nopmt = Convert.ToDecimal(numpmts.Text);
    nopmt = nopmt * nopymts2;
    sb.Clear();
    sb.Append("$");
    sb.Append(nopmt.ToString("#.00"));
    nopymts.Text = sb.ToString();



    ValidateCC();
    chkNewCC();

    bool crdcrd = credCard;
    bool newcrd = nwCard;


    if (!IsPostBack){

    }

}

1 个答案:

答案 0 :(得分:2)

您正在检查IsPostBack,但在检查前您仍然在进行所有重置操作!然后检查没有区别,因为它是一个空的条件块!你应该这样做:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        // All the initial setup that you don't want to do again goes here.
    }

    // All the stuff you want to do on first load AND PostBack goes here.
}

确保understand how conditionals work