RadioButton1触发事件

taylermail 2011-04-07 04:52:48
<asp:RadioButton id=RadioButton1 runat="server" GroupName="Sl">
</asp:RadioButton
当RadioButton1选中时触发事件怎么写
...全文
137 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxing2006 2011-04-07
  • 打赏
  • 举报
回复
属性 AutoPostBack = true
CheckOnchange事件
耗子哭死猫 2011-04-07
  • 打赏
  • 举报
回复
微软官方示例代码

/************************************* Module Header **************************************\
* Module Name: MainForm.cs
* Project: CSWinFormGroupRadioButtons
* Copyright (c) Microsoft Corporation.
*
* This sample demonstrates how to group the RadioButtons in the different containers.
*
* For more information about the RadioButton control, see:
*
* Windows Forms RadioButton control
* http://msdn.microsoft.com/en-us/library/f5h102xz.aspx
*
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\******************************************************************************************/

using System;
using System.Windows.Forms;

namespace CSWinFormGroupRadioButtons
{
public partial class MainForm : Form
{
// store the old RadioButton
//第一步创建一个RadioButton控件的对象
private RadioButton radTmp = null;

public MainForm()
{
InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
// we checked the rad1 in the MainForm.Designer.cs file
// then this RadioButton would be the old one
//第二步在初始加载的时候rad1为选中状态
radTmp = this.rad1;
}

// let the 4 Radiobuttons use this method to deal with their CheckedChanged event
// in the MainForm.Designer.cs file

//每当更改属性值的时候触发事件
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
// uncheck the old one
//第三步当点击其他RadioButton更改了属性值状态的时候,其他RadioButton控件为未选中,在根据参数选中状态,Lable控件显示的是当前控件选中的Name;
radTmp.Checked = false;
radTmp = (RadioButton)sender;

// find out the checked one
//这个是处理相同的业务
if (radTmp.Checked)
{
this.lb.Text = radTmp.Name + " 当前被选中的控件";
}
//这个是单独处理业务
if (rad1.Checked)
{
//rad1被选中处理业务
}
else if (rad2.Checked)
{
//rad2被选中处理业务
}
}

}
}

耗子哭死猫 2011-04-07
  • 打赏
  • 举报
回复

//每当更改属性值的时候触发事件
private void radioButton_CheckedChanged(object sender, EventArgs e)
taylermail 2011-04-07
  • 打赏
  • 举报
回复
如何写?
if (this.RadioButton1.Checked == true) { this.RadioButton1.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='A'"); }
if (this.RadioButton2.Checked == true) { this.RadioButton2.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='B'"); }
if (this.RadioButton3.Checked == true) { this.RadioButton3.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='C'"); }
if (this.RadioButton4.Checked == true) { this.RadioButton4.InputAttributes.Add("onclick", "parent.left.document.getElementById('" + id + "').innerText='D'"); }
兔子-顾问 2011-04-07
  • 打赏
  • 举报
回复
写 OnClick
关于这个问题,百度里说法纷纷,大都无用,或者说版本太老太罗嗦,这里介绍一个可借鉴的用法: 按理说,页面上的若干个Radio Button 在页面加载初始化时,是默认选中第一个的,但总是避免不了一些特殊的需求——所有的单选按钮都不选中,仅当用按钮触发事件时再去做必选校验。例如:
2023/6/4 ASP.NETWeb服务器控件 ASP全文共74页,当前为第1页。 ASP.NET提供的Web效力器控件简化了Web运用顺序的设计进程。 Windows控件的属性、方法、事情都是在本机上执行的; Web效力器控件的属性、方法、事情那么全部是在效力器端执行的。 在Web运用顺序中,用户经过客户端阅读器操作Web页面时,对Web效力器控件的每个央求都要发送到效力器端,效力器中止处置后,再将处置结果转换为客户端脚本发送到客户端显示。 由于客户端的每个央求都要经过网络发送到效力器处置,会对网络传输带来很大的担负。 Windows控件与Web效劳器控件的主要区别 ASP全文共74页,当前为第2页。 14.1 规范控件 14.1.1 复杂控件 Button、TextBox、CheckBox CheckBoxList、RadioButton RadioButtonList、ListBox DropDownList 14.1.2 Table控件 14.1.3 HiddenField控件 ASP全文共74页,当前为第3页。 14.1.1 复杂控件 Button控件 有三种类型的按钮控件: Button控件:与Windows窗体的Button控件用法相反。 LinkButton控件:外观与Hyperlink控件相反,但在功用上与Button控件完全相反。 ImageButton控件:经过属性[ImageUrl]指定显示在按钮的图片。 三种类型的按钮在鼠标单击时都可以将窗体提交给效力器,并触发效力器端对应的Click事情,然后在效力器端执行相应的事情代码。 ASP全文共74页,当前为第4页。 TextBox控件 TextBox控件用于在Web页面中接纳如入的文本内容。 1. 常用的基本属性 1) AutoPostBack属性:决议控件中文本修正后,能否自动回发到效力器。该属性默许值为false,即修注释本后并不立刻回发到效力器,而是等窗体被提交后一并处置。 2) TextMode属性:用于设置文本框接受文本的行为方式。共有三种属性值:MultiLine〔多行输入方式〕;Password〔密码输入方式〕;SingleLine〔单行输入方式〕。默许状况下,该属性为SingleLine。 2. 常用的事情 TextChanged事情:文本框的内容发作更改招致窗体回发效力器时触发。 留意,能否触发该事情与AutoPostBack属性有关。 ASP全文共74页,当前为第5页。 CheckBox控件与CheckBoxList控件  CheckBox控件:向用户提供一组可选项。 CheckBoxList控件:向用户提供一组选项,也叫复选框。在运转时静态的决议有哪些选项时,运用CheckBoxList控件比拟方便。 ASP全文共74页,当前为第6页。 CheckBox控件与CheckBoxList控件〔续〕 1. CheckBox控件的常用基本属性 AutoPostBack属性:决议CheckBox控件外形更改后能否自动回发到效力器处置。该属性默许值为false。 2. CheckBoxList控件的常用基本属性 1) Items属性:表示控件对象中一切项的集合。 2) RepeatColumns属性:指示控件中显示CheckBox项的列数。 3) RepeatDirection属性:决议控件中各CheckBox项的显示方法。默许值是Vertical。该属性值还可以修正为Horizontal,使各项按水平方式陈列显示。 3. CheckBoxList控件的常用基身手情 CheckedIndexChanged事情:更改CheckBoxList控件中的选项,回发效力器时触发。 ASP全文共74页,当前为第7页。 RadioButton控件与RadioButtonList控件 RadioButton效力器控件与Windows控件的区别: 在Windows窗体中,在同一容器中的一切RadioButton控件都默以为同一组,只能在这些控件中中止单项选择; Web窗体中,默许状况下会将同一容器中的一切RadioButton效力器控件作为不同组,可以多项选择。假定希望将其作为一组,需求设置RadioButton 的GroupName属性。 ASP全文共74页,当前为第8页。 RadioButton控件与RadioButtonList控件〔续〕 RadioButton控件的GroupName属性:运用该属性指定一个单项选择按钮组,以创立一组互斥的控件。 RadioButtonList效力器控件是封装了一组单项选择按钮控件的列表控件。其主要的属性、事情与CheckBoxList效力器控件相反。 ASP全文共74页,当前为第9页。 ListBox控件 ListBox

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧