即使自动回发为真,也不会触发单选按钮事件 [英] radio button event is not fired even when auto post back is true

查看:47
本文介绍了即使自动回发为真,也不会触发单选按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个aspx页面

 <%@       标题  =    语言  =  C#    MasterPageFile   = 〜/ UserArea /MainMaster.master\"   AutoEventWireup   =   true    CodeFile  < span class =code-keyword> =  Default.aspx.cs   继承  =  _默认   %>  

< span class =code-keyword>< asp:Content ID = Content1 ContentPlaceHolderID = head Runat = < span class =code-keyword>服务器 >
< / asp:Content >
< asp:内容 ID = Content2 ContentPlaceHolderID = ContentPlaceHolder1 Runat = 服务器 >
< p >
< br / >
< asp:RadioButton ID = RadioButton1 runat = server AutoPostBack = True < span class =code-attribute>

< span class =code-attribute> 已检查 = True GroupName = oncheckedchanged = RadioButton1_CheckedChanged / >
< ; asp:RadioButton ID = RadioButton2 runat = server AutoPostBack = True

GroupName = oncheckedchanged = R adioButton2_CheckedChanged / >
< / p >
< p >
< / p >
< / asp:Content >



和c#file

  public   partial   class  _Default:System.Web.UI.Page 
{
受保护 void Page_Load( object sender,EventArgs e)
{
if (!IsPostBack)
RadioButton2.Checked = < span class =code-keyword> true ;
}
受保护 void RadioButton1_CheckedChanged( object sender,EventArgs e)
{
// code block
}
protected void RadioButton2_CheckedChanged(对象发​​件人,EventArgs e)
{
// 代码块
}
}





事件单选按钮检查更改不会在我点击时触发单选按钮.plz help.i在另一个页面的编辑模式下遇到同样的问题。

解决方案

如果你想在默认情况下检查radiobutton1那么你可以删除代码在页面加载时将radiobutton2设置为true,以便触发事件。


由于两个单选按钮(在页面加载和aspx页面中)的checked属性设置为true,因此未触发checkedchanged事件。





谢谢

Hari


我试过你的代码。当我删除Radiobutton1的checked属性的默认值时,事件将正常触发。请尝试使用Radiobutton1

< asp:RadioButton ID =   RadioButton1 runat =   server AutoPostBack =   True 
GroupName = a oncheckedchanged = RadioButton1_CheckedChanged />


i have an aspx page

<%@ Page Title="" Language="C#" MasterPageFile="~/UserArea/MainMaster.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        <br />
        <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"

            Checked="True" GroupName="a" oncheckedchanged="RadioButton1_CheckedChanged" />
        <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"

            GroupName="a" oncheckedchanged="RadioButton2_CheckedChanged" />
    </p>
    <p>
    </p>
</asp:Content>


and c# file

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        RadioButton2.Checked = true;
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
//code block
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
//code block
    }
}



event radio button checked change is not fired when i clicked on the radio button .plz help.i suffer same problem in edit mode of another page.

解决方案

if you want the radiobutton1 to be checked by default then you can remove the code on page load to set the radiobutton2 checked as true that should fire the event.

Since the checked property is set to true for both the radiobuttons (in page load and the aspx page) the checkedchanged event is not being fired.


Thank you
Hari


I tried your code. When i remove the default value for checked property for Radiobutton1 then the event fires properly. Please try this for Radiobutton1

<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
GroupName="a" oncheckedchanged="RadioButton1_CheckedChanged" />


这篇关于即使自动回发为真,也不会触发单选按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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