Search code examples
c#gridviewpostbackpageloadautopostback

Do I need to get rid of a postback or?


I've got a problem with my code.

I have this in my page load:

result = objdboDoc.searchFattura(Convert.ToInt64(Session["id_utente"]), id_cliente);

what does it do? Well I have a gridview on the top of the page which shows me all the invoices a user submitted for a customer. so I call the stored procedure "Look for invoices" made by "user", to "customer".

I have an another gridview in the middle of the page with all my customers. When I click on "Select customer", the page is being posted back, and then I get the id of the customer I want to show my invoices for. Since the page is posted back before executing the "Select customer" command, when I click select I still have the invoices of the old customer. Only if I click select again I get the right customer's id

It's mind blowing because I need

 result = objdboDoc.searchFattura(Convert.ToInt64(Session["id_utente"]), id_cliente); 

to load the invoices of the customer selected in the previous page


Solution

  • first, the page is not posting back before "Select Customer" it's posting back because of the click.

    After you process the select from the middle grid and choose a customer I assume that someplace you are setting Session["id_utente"] which is used by the first grid. after setting the session variable it should just be a matter of rebinding the first grid with a call to DataBind.

    Page Life Cycle