在ASP.net中使用单选按钮 [英] Radiobutton use in ASP.net

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

问题描述

在我的表单中,我有两个单选按钮rdbtn1和rdbtn2
现在当我选择rdbtn1 textbox1 nd textbox2时应禁用(启用textbox3 nd textbox4).当我选择rdbtn2 textbox3 nd textbox4时应禁用(textbox1 nd textbox2启用)

OP的答案移至此处:



我在C#中尝试了相同的逻辑(当我是新开发者plz帮助时)

In my form I am having two radionbutton rdbtn1 and rdbtn2
now when I select rdbtn1 textbox1 nd textbox2 should be disabled (textbox3 nd textbox4 enabled).and when I select rdbtn2 textbox3 nd textbox4 should be disabled ( textbox1 nd textbox2 enabled)

OPs answer moved to here:

Hi ,

I tried the same logic in C# (As i m new developer plz help)

protected void rbtnParent_CheckedChanged(object sender, EventArgs e)
{
   txtChildRouteList.Enabled = false;
   btnAdd.Enabled = false;
   btnDelete.Enabled = false;
   lstbxChildRoute.Enabled = false;
   Panel1.Enabled = false;
 
   drpdwnOrigin.Enabled = true;
   drpdwnDest.Enabled = true;
}


bt无法获得输出..意味着如果我选择任何单选按钮,则不会发生任何更改


bt not getting the output..means if i select any radio button no change is happen

推荐答案

First of all you must set the same group property to both your radiobuttons 

select the radiobutton and go to property set the group property something like"a"

select the other radiobutton and set the same property "a"

Now your radiobuttons will not checked together.

Protected Sub rdbtn1_CheckedChanged(sender As Object, e As EventArgs) Handles radShowInvoiceTotal.CheckedChanged

            textbox1 .Enabled = True
            textbox2 .Enabled = True
            textbox3 .Enabled = False
            textbox4 .Enabled = False
  
End Sub


Protected Sub rdbtn2_CheckedChanged(sender As Object, e As EventArgs) Handles radShowInvoiceTotal.CheckedChanged
 
            textbox1 .Enabled = False
            textbox2 .Enabled = False
            textbox3 .Enabled = True
            textbox4 .Enabled = True


End Sub


您可以使用一些可响应单选按钮的onclick事件的JavaScript来实现此目的.这样一来,您就不必在每次点击时都回发.
You can do this with a little javascript that responds to the onclick event of the radiobutton in question. That way you don''t have to postback on every click.


使用Java脚本执行操作,可以提高代码性能.

看下面的例子
Do it using Javascript, it will improve your code performance.

look following example
if(document.getElementById("CHK1").checked)
{
   document.getElementById("TEXTBOX1").disabled = false;
   document.getElementById("TEXTBOX2").disabled = false;
   document.getElementById("TEXTBOX3").disabled = true;
   document.getElementById("TEXTBOX4").disabled = true;
}


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

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