View Single Post
  #4 (permalink)  
Old May 23rd, 2010, 02:33 PM
chroniclemaster1 chroniclemaster1 is offline
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

This is a problem where you just need to figure out what goes where. It sounds like you have all the pieces it's a challenge putting them together. Without code samples, I can't tell for sure, but I suspect you've set your code up like a lot of the MSDN samples...

Code:
... Page_Load(...)
{
   // Do stuff everytime page loads


   if (!IsPostBack)
   {
      // Only do stuff when page loads the FIRST time
   }
   else
   {
      // Only do stuff when page loads the second time (or third, fourth, etc.)
   }

}
That's fine when you only have one button on the page. You use the if statement for decision making and you test the IsPostBack property of the page to determine if this is the first time the page has posted back or not. Note that you can do things EVERY time the page loads, they just go outside that if-else test. However, you are only testing the postback property. You can't tell this way which button

However, you have two buttons. You need to use an alternate code organization...


Code:
... Page_Load(...)
{
   // Do stuff everytime page loads
}

... Button1_click(...)
{
   // Do stuff only when the page posts back because button ONE was clicked. You can write all your code here, or you can encapsulate parts of the code in other private functions like this
callMyOtherEncapsulatedFunction();
}

... Button2_click(...)
{
   // Do stuff only when the page posts back because button TWO was clicked. You can even call custom classes in a library file...

CustomClassInLibrary newClass = new CustomClassInLibrary();
newClass.callMyFunctionInTheCustomClass();
}

private ... callMyOtherEncapsulatedFunction()
{
   // Do lots of complicated stuff that you didn't want to have to code in the click event, or the you encapsulated for reuse, code clarity, or to provide better abstraction in your application. Yet, since only the Button1 click event calls this function, it ONLY happens when Button1 has been clicked.
}
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
The Following User Says Thank You to chroniclemaster1 For This Useful Post:
Gayathri79 (May 24th, 2010)