Click here to Skip to main content
15,887,355 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I'm calling a method on form load that will populate a variable with a value, I want it to be called only when the page loads the First time not when a button is clicked or the page refreshes is that possible

Thank u in advance
Posted
Updated 25-Jul-12 22:18pm
v2
Comments
StianSandberg 26-Jul-12 4:02am    
asp.net webforms or windows forms?
mlingo209 26-Jul-12 4:08am    
asp.net webforms the method will populate a variable with a unique QuoteNo then on the same page the user will have a button to add products to quote which must update the amount textbox using the same QuoteNo for every product added Thank u in advance.

C#
protected void Page_Load(object sender, EventArgs e)
{

  string quoteNo;

  if(!IsPostBack)
  {
     quoteNo = Convert.ToString(Session["QuoteNo"]);
     if(string.IsNullOrEmpty(quoteNo)){
       // generate quoteNo and put it in a session variable
       quoteNo = GenerateQuoteNo();
       Session["QuoteNo"] = quoteNo; 
       // use your quoteNo
     }
  }
  else
  {
     quoteNo = Convert.ToString(Session["QuoteNo"]);
     // use your quoteNo
  }
}
 
Share this answer
 
v2
Comments
mlingo209 26-Jul-12 4:22am    
Thank u I think this is exactly what I was looking for.
StianSandberg 26-Jul-12 4:34am    
good for you :)
Try this:

On the page load event of your page.

C#
if(!IsPostBack)
{
//code for very first load//
}
else
{
//not first load//
}


hope it helps :)
 
Share this answer
 
Comments
mlingo209 26-Jul-12 4:10am    
Will this work when the person navigates to the page again because I want the user to be able to get a new value when a creating a different quote.
Uday P.Singh 5-Aug-12 14:27pm    
yes it will.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900