Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <asp:Button ID="bttnCounter" runat="server" Text="Click Me" OnClick="ButtonClick"/>
  2.  
  3. Counter counter = new Counter();
  4.  
  5. protected void Page_Load(object sender, EventArgs e)
  6. {
  7. bttnCounter.Click += new EventHandler(this.ButtonClick);
  8. }
  9.  
  10. public void ButtonClick(Object sender, EventArgs e)
  11. {
  12. counter.CountUp();
  13. output.Text = "The count is " + counter.CurrentCount;
  14. }
  15. }
  16.  
  17. public class Counter
  18. {
  19. public int CurrentCount { get; private set; }
  20.  
  21. public Counter()
  22. {
  23. CurrentCount = 0;
  24. }
  25.  
  26.  
  27. public void CountUp()
  28. {
  29. CurrentCount++;
  30. }
  31. }
  32.  
  33. this.ViewState["someVar"] = yourObject;
  34.  
  35. YourClass yourObject = (YourClass)this.ViewState["someVar"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement