Button causing post

  • Thread starter Thread starter Brian Shannon
  • Start date Start date
B

Brian Shannon

How can I tell the name of the button causing the post. I have some code in
page prerender and I don't want the code to execute if a certain button
causes the post since it would be an unnecessary trip to the server and a
hit on the DB.

If button <> btnTime caused post then
Execute Code
End if

Thanks
 
Could you just to a
if(!IsPostBack){}

Or do you have to do the redener with some buttons? If so just put the call
to do this in the buttons you need it to, it'll be easier.
 
Thanks for the quick response Curt. My situition is that I have a datagrid
on a page and a composite control made up of a calandar control and a text
box. When the user selects a new date I need the datagrid to update based
on the new selected date.

When the processing begins the page load is fired and then my composite
control is fired so I can't use the ispostback because the page is loaded
before my new date is selected. That is why I put the databind method for
the datagrid in the prerender so the datagrid will update after the date is
selected in the composite control.

I have two other buttons on the page that cause postback and the datagrid is
redrawn in the prerender method which is unnecessary for my purposes.

So if possible I don't want the code in prerender to execute if either of
these two buttons are presses.

Is there another way to get my datagrid to be redrawn/binded after the
composite control is executed?

Thanks
 
The button pressed will be the sender argument passed to your event handler,
just do a:

Button foo = (Button)sender;
if(foo.ID != "bar")
//do stuff


MattC
 
Back
Top