c# - TimeSpan still not working -


heres code have re arranged, still have same problem, not able find start , end times on last page? how do this?

public void start()     {         datetime starttime = datetime.now;     }      protected void btnstart_click(object sender, eventargs e)     {         start();         response.redirect("~/end.aspx");     } 

public void end()     {         datetime endtime = datetime.now;     }     protected void btnend_click(object sender, eventargs e)     {         end();         response.redirect("~/display.aspx");     } 

public partial class display : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {         timespan timespent = endtime - starttime;          lbldisplay.text = string.format("time: {0}", timespent);     } } 

now can me on this? should use session, if should, how use datetime , timespan, etc. thanks!

problem : declaring starttime , endtime variables inside functions below:

public void start() {     datetime starttime = datetime.now; //remove declartion here }  public void end() {     datetime starttime = datetime.now; //remove declaration here } 

solution : declare starttime , endtime variables class variables , assign values in start() , end() functions.

try this:

datetime starttime; //declare here datetime endtime;   //declare here  public void start() {     starttime = datetime.now; //assign value here } public void end() {     endtime = datetime.now;  //assign value here } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -