Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 2 asp buttons and using the C# as the code behind..

ASP
ASP.NET
<asp:Button ID="Options1" runat="server" Text="Option1" OnClick="toggle_Click" />
<asp:Button ID="Options2" runat="server" Text="Option2" OnClick="toggle_Click" />

C#
C#
protected void toggle_Click(object sender, EventArgs e)
       {
           Button button = (Button)sender;

           if (button.ID == "Options1")
           {
               Panel1.Visible = false;
               Panel2.Visible = true;
           }
           else if (button.ID == "Options2")
           {
                Panel1.Visible = true;
               Panel2.Visible = false;
           }
          else
          {
             //do nothing implementation
          }
       }

The problem I am facing is:
When I click Options2 and then clicking the Option1 is trigerring fine. But the reverse not trigerring the Options2.. I dont know whats the logic that laggs it behind.. Please do prefer any favourable solutions..
Posted
Comments
Devang Vaja 11-Mar-13 1:05am    
the problem is that same event is not firing on both button click
Janani Muthaiyan 11-Mar-13 1:08am    
But why? Is there any thing that I did wrong?.. I did the same thing for radio buttons it is working fine along with the property of AutoPostBack="true"..
pradiprenushe 11-Mar-13 1:19am    
Your code is fine use debugger to solve problem. No need to separate events.
Janani Muthaiyan 11-Mar-13 1:23am    
@Devang Vaja.. You are right.. It couldn't resolve its ID.. Thank you for the solution.. It works good now..
pradiprenushe 11-Mar-13 1:23am    
Are you doing any code in pageload?

1 solution

put two click events separate and call a function from both.. 
like button_Click 
{ Button button = (Button)sender; 
myfunction(button); } 
button1_Click
 { Button button = (Button)sender; my function(button); }
 protected void myfunction(Button button)
 { if (button.ID == "Options1") 
{ Panel1.Visible = false; Panel2.Visible = true; } 
else if 
(button.ID == "Options2")
 { Panel1.Visible = true; Panel2.Visible = false; } 
else
 { //do nothing implementation }
 }
 
Share this answer
 
Comments
Devang Vaja 11-Mar-13 1:52am    
thnx all of you for downvoting my answer..:)
SHUBH CODING
Janani Muthaiyan 13-Mar-13 2:01am    
The above code doesn't working.. Any other solutions???
Devang Vaja 13-Mar-13 2:48am    
then you code is ok...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900