在asp.net中调用的方法 [英] Method calling in asp.net

查看:99
本文介绍了在asp.net中调用的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个单选按钮和四个方法。当我单击一个单选按钮时,应该调用适当的方法并在ASP.NET中使用标签显示结果(带有c#.net的asp.net)。



先谢谢

I have four radio buttons and four method.when I click a radio button appropriate method should be called and display result in label in ASP.NET(asp.net with c#.net).

Thanks in Advance

推荐答案

1。使用 OnCheckedChanged 事件(当Checked属性发生变化时要执行的函数的名称)单选按钮。



2.在所有单选按钮上为该事件调用相同的功能。



3.在这种情况下,检查单击了哪个单选按钮。



4.在标签上显示该单选按钮。



参考 - 如何在RadioButton中使用OnCheckedChanged事件 [ ^ ],它提供了类似的要求。



因此,在您的aspx中,Radio Buttons将如下所示。

1. Use OnCheckedChanged event (the name of the function to be executed when the Checked property has changed) of Radio Button.

2. Call the same function on that event for all Radio Buttons.

3. In that event, check which radio button is clicked.

4. Show in label about that Radio Button.

Refer - How to use OnCheckedChanged event in RadioButton[^], which gives similar type of requirement.

So, in your aspx, Radio Buttons will look like below.
<asp:RadioButton

             ID="RadioButton1"

             runat="server"

             Text="RadioButton1"

             OnCheckedChanged="RadioButton_CheckedChanged"

             AutoPostBack="true">
</asp:RadioButton>
<asp:RadioButton

             ID="RadioButton2"

             runat="server"

             Text="RadioButton2"

             OnCheckedChanged="RadioButton_CheckedChanged"

             AutoPostBack="true">
</asp:RadioButton>
<asp:RadioButton

             ID="RadioButton3"

             runat="server"

             Text="RadioButton3"

             OnCheckedChanged="RadioButton_CheckedChanged"

             AutoPostBack="true">
</asp:RadioButton>
<asp:RadioButton

             ID="RadioButton4"

             runat="server"

             Text="RadioButton4"

             OnCheckedChanged="RadioButton_CheckedChanged"

             AutoPostBack="true">
</asp:RadioButton>





所以,你可以看到fu所有单选按钮的' OnCheckedChanged 事件调用RadioButton_CheckedChanged



现在在cs页面中,如下所示。



So, as you can see the function "RadioButton_CheckedChanged" is called for all Radio Buttons'' OnCheckedChanged Event.

Now in cs page, do like below.

protected void RadioButton_CheckedChanged(object sender, System.EventArgs e)
{
      if (RadioButton1.Checked)
      {
            // Call function you want to call for "RadioButton1".
            Label1.Text = "You choose: " + RadioButton1.Text;
      }

      if (RadioButton2.Checked)
      {
            // Call function you want to call for "RadioButton2".
            Label1.Text = "You choose: " + RadioButton2.Text;
      }
      
      if (RadioButton3.Checked)
      {
            // Call function you want to call for "RadioButton3".
            Label1.Text = "You choose: " + RadioButton3.Text;
      }
      
      if (RadioButton4.Checked)
      {
            // Call function you want to call for "RadioButton4".
            Label1.Text = "You choose: " + RadioButton4.Text;
      }
}


这篇关于在asp.net中调用的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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