Button click happens twice

Results 1 to 2 of 2

Thread: Button click happens twice

  1. #1
    Join Date
    Dec 1969

    Default Button click happens twice

    Hi all<BR><BR>I am probably asking a logic question.<BR><BR>The scenario is that<BR><BR>I have a web page with just a placeholder<BR>I have 2 web user controls<BR>programmatically I want to show either of the web user control at any point.<BR><BR>one web user control has a dbgrid inside another dbgrid and the inner dbgrid has a button column.<BR><BR>The other web user control has a some text and a button<BR><BR>I choose which web user control to display thro a session variable which I populate whenever any button is clicked.<BR><BR>So far every thing is working correctly with just one problem, i.e. when I click a button the first time, nothing really happens but the page does go to the server and comes back. So in effect the same web user control is displayed again. Only when I click the button again, then I get the other web user displayed.<BR><BR>Ideally on a single click, the placeholder should switch web user control.<BR><BR>I also know why, it is happening. This is because, when you click on the button, then events that occur is in the order of <BR>web form load <BR>web user load <BR>and then finally button click<BR>(I have left out other event for the sake of simplicity)<BR><BR>That is the reason why the session variable is populated after the web form is loaded the first time after a click on the button.<BR><BR>Any solution will be appreciated

  2. #2
    Join Date
    Dec 1969
    Indianapolis, IN

    Default RE: Button click happens twice

    Anytime I get into sticky situations like these, I make sure that I&#039;m checking the Page.IsPostBack value. If it&#039;s true, the page has posted back to itself. If it&#039;s false, this is the first time the user has gone to the page. You might want to make use of Page.IsPostBack in the loads. Hope that helps!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts