简体   繁体   中英

RadioButtonList SelectedIndexChanged not firing everytime

I have a RadioButtonList control in asp.net UserControl. It has 2 Radio buttons "Leave" and "Available". On click of Leave, I display alert from SelectedIndexChanged event as "Are you sure you want to take Leave?" with Ok and Cancel buttons. On click of Cancel, it will automatically select "Available". Upto this it is fine.

Step 1: User Clicks Cancel restores to "Available"

Step 2: When User again clicks "Leave", it will not display alert from SelectedIndexChanged of RadioButton.

Step 3: Now it will work again.

For this I have enabled EnableViewState="true" for that UserControl. But still it does not work for the 2nd time.

Below is the Server side SelectedIndexChanged event

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, "");
    }
}

This is the javascript code

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;
    }
}

Use the following code and let me know the result

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM