【问题标题】:RadioButtonList SelectedIndexChanged not firing everytimeRadioButtonList SelectedIndexChanged 每次都不会触发
【发布时间】:2017-02-13 14:59:41
【问题描述】:

我在 asp.net UserControl 中有一个 RadioButtonList 控件。它有 2 个单选按钮“离开”和“可用”。单击离开时,我将来自 SelectedIndexChanged 事件的警报显示为“您确定要休假吗?”带有确定和取消按钮。单击取消时,它将自动选择“可用”。到此为止还好。

第 1 步:用户单击“取消”恢复为“可用”

第二步:当用户再次点击“离开”时,它不会显示来自 RadioButton 的 SelectedIndexChanged 的​​警报。

第 3 步:现在它又可以工作了。

为此,我为该用户控件启用了 EnableViewState="true"。但是第二次还是不行。

下面是Server端SelectedIndexChanged事件

protected void rdlUser_SelectedIndexChanged(object sender, EventArgs e)
{
    if (rdlUser.SelectedIndex == 1)
    {
        txtUser.Enabled = true;
    }
    else
    {
        radWindowManager.RadConfirm("Are you sure you want to take Leave?", "confirmSave" + this.ClientID, 300, 100, null, "");
    }
}

这是javascript代码

function confirmSave<%=this.ClientID%>(arg) {
    if (arg == true) {

        $find('<%= FindControl("txtUser").ClientID %>').set_value("");

    }
    else {
        var rdlUser = document.getElementById("<%= rdlUser.ClientID %>");
        var radioButtons = rdlUser.getElementsByTagName('input');
        radioButtons[3].checked = true;
    }
}

【问题讨论】:

  • 对于第 2 步,如果您默认选择返回离开选项,则当您再次单击此选项时不会触发 SelectedIndexChanged 事件。该事件仅在所选选项与您之前的选择不同时触发。您不使用客户端方法有什么特别的原因吗?
  • 我在这里使用 Telerik RadConfirm。有什么解决办法吗?

标签: c# asp.net telerik


【解决方案1】:

使用下面的代码告诉我结果

function confirmSave<%=this.ClientID%>(arg) {
    if (arg == true) {
        $find('<%= FindControl("txtUser").ClientID %>').set_value("");
        return true;
    }
    else {
        var rdlUser = document.getElementById("<%= rdlUser.ClientID %>");
        var radioButtons = rdlUser.getElementsByTagName('input');
        radioButtons[3].checked = true;
        return false;
    }
}

【讨论】:

  • radWindowManager.RadConfirm("你确定要请假吗?", "return confirmSave" + this.ClientID +";", 300, 100, null, ""); }
  • 这对我不起作用@Kiran。现在我没有收到确认消息框。
  • 如果只能在客户端使用&lt;button onclick="radconfirm('Are you sure?', confirmCallBackFn); return false;"&gt; show radconfirm&lt;/button&gt;可以吗
  • 如果只能在客户端完成
猜你喜欢
  • 2017-02-16
  • 2011-07-29
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-29
相关资源
最近更新 更多