Paul T. Rykiel
Paul T. Rykiel

Reputation: 1227

How does the Post back get reset ?

Let me elaborate on this... I have the code below, there is a Page_Init (which I still don't understand why it fires more than once, but that is another story), and a Page_Load and I am checking for the "isPostBack" ... everything works great while I use my controls, radio button and drop down list, as well as Buttons; however, if I press the key, even accidentally, the "isPostBack" is reset to False. What am I doing wrong? Also, my AutoEventWireup="true". Also, this is an .ascx file.

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){

    }

}

Upvotes: 0

Views: 49

Answers (1)

Ant P
Ant P

Reputation: 25231

You're checking IsPostBack but you're still doing all the resetting before the check! And then the check makes no difference because it's an empty conditional block! You should be doing this:

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.
}

Make sure you understand how conditionals work.

Upvotes: 2

Related Questions