Asp Button不会触发事件 [英] Asp Button does not fires up an event

查看:101
本文介绍了Asp Button不会触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个asp按钮并使用C#作为代码...



ASP

I have 2 asp buttons and using the C# as the code behind..

ASP

<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
          }
       }



我面临的问题是:

当我单击Options2然后单击Option1时,可以正常运行。但反过来并没有试图选择2 ..我不知道什么是落后于它的逻辑..请确实更喜欢任何有利的解决方案..


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..

推荐答案

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 }
 }


这篇关于Asp Button不会触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆