Click here to Skip to main content
11,929,675 members (56,964 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET buttons
I have 2 asp buttons and using the C# as the code behind..

<asp:Button ID="Options1" runat="server" Text="Option1" OnClick="toggle_Click" />
<asp:Button ID="Options2" runat="server" Text="Option2" OnClick="toggle_Click" />
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;
             //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 10-Mar-13 19:50pm
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?
Janani Muthaiyan 11-Mar-13 1:23am
Devang Vaja 11-Mar-13 1:39am
to fir answer acceptance banta he janani ji:)
pradiprenushe 11-Mar-13 1:40am
your code working on my site. Can you paste total .aspx page & code?
Devang Vaja 11-Mar-13 1:41am
Janani Muthaiyan 11-Mar-13 1:45am
@pradiprenushe Yes when I put in to separate file it works with my code itself.. When I implement it large application It couldn't fire up since I have lot of button clicks to same method to call on click.. But the implementation is done by matching its id.. Since it is privacy i can post the entire code and sorry for that..

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

put two click events separate and call a function from both.. 
like button_Click 
{ Button button = (Button)sender; 
myfunction(button); } 
 { 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; } 
 { //do nothing implementation }
Devang Vaja 11-Mar-13 1:52am
thnx all of you for downvoting my answer..:)
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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 11 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100