0

Hi everyone i have a strange problem which I hope u can help me with, i have a normal Asp.net page in which i handle some state data in the page load like this

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["TempD"] = null;
            Session["Totals"] = null;
            //Handling Sessions here...
        }
    }

the problem is at a button post back the page_load gets called twice once with IsPostBack = true which is ok , the second time however IsPostBack = false!!! which cause my code to enter the if condition and reset the state information which is not ok, i use some Ajax Toolkit controls in the page no update panels just some calenders and AutoCompletes. here is the code for the button causing the post back

protected void TSBtnAddItem_Click(object sender, EventArgs e)
    {
        if (Session["TempD"] != null)
        {
            DataLayer.Invoicing.CInvoiceDetail InvoDetails = (DataLayer.Invoicing.CInvoiceDetail)Session["TempD"];
            DataLayer.Invoicing.CVarInvoiceDetail var = new DataLayer.Invoicing.CVarInvoiceDetail();
            if (LblCurrencyValue.Visible)
            {
                var.CurencyID = int.Parse(LblCurrencyValue.ToolTip);
            }
            else
            {
                var.CurencyID = int.Parse(CboCurrencyValue.SelectedValue);
            }
            var.ID = 0;
            var.InvoiceHeaderID = Convert.ToInt64(InvoiceHeaderID.Value);
            var.IsChanges = true;
            var.IsFreightItem = false;
            var.IsOption = true;
            var.ItemAmount = decimal.Parse(txtItemVal.Text);
            var.ItemName = CboItemName.SelectedItem.Text;
            var.ItemID = int.Parse(CboItemName.SelectedValue);
            var.Remarks = "";
            if (IsPartLoad.Checked == true)
            {
                ShipLink.Publics.ApplicationMethods.Item32 itm = LstCalcType.Find(delegate(ShipLink.Publics.ApplicationMethods.Item32 p1) { return Convert.ToInt32(p1.Name.Trim()) == var.ItemID; });
                if (itm == null)
                {
                    ADDToCalcList(Convert.ToString(var.ItemID));
                    if (NumUpDownPortRatio.Enabled == false)
                        var.ItemAmount = ChangeAmount(var.ItemID, var.ItemAmount);
                }
            }
            InvoDetails.lstCVarInvoiceDetail.Add(var);
            Session["TempD"] = InvoDetails;
            UGrdInvoiceDetailGrid.DataSource = InvoDetails.lstCVarInvoiceDetail;
            UGrdInvoiceDetailGrid.DataBind();
            CalcSalesTax();
            CalcDiscount();
            AddCaseUGrdInvoiceTotalGrid();

        }
    }
Khaled Saleh
  • 1
  • 1
  • 1
  • I should add that if i add for example a check box and change the Checked property to true in the button event< in the second post back its Checked =false which means the second Post back happens for a different "instance" of the page that does not even have the same view state and i have no idea why is that happening :/ – Khaled Saleh Jun 24 '13 at 11:07
  • thanks i found the problem in the master page i was using " /> i seems ResolveUrl() was causing the issue replaced it with relative url and all is fine – Khaled Saleh Jun 24 '13 at 12:38

2 Answers2

0

Have a look at this: What is the difference between Page.IsPostBack and Page.IsCallBack?

Integrate if (!IsCallBack) and you should be fine.

Community
  • 1
  • 1
Mark Rae
  • 11
  • 3
0

I found a solution for this. If you have an global.asax in the project, you need add a new route with "" in a url alias. An example:

private void Generteroutes(RouteCollection routes) {
                routes.MapPageRoute("home", "", "~/Default.aspx");
}

load this in Application_Start and problem solved.

Trudbert
  • 3,178
  • 14
  • 14