Click here to Skip to main content
15,912,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am trying to dispaly a confirm msg for a radio button which is having
two list items as below:

XML
<asp:RadioButtonList ID="rbtnDataMatch" runat="server" RepeatDirection="Horizontal"
                            style="font-size:10pt;" AutoPostBack="true"
                            onselectedindexchanged="rbtnDataMatch_SelectedIndexChanged" >
                   <asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
                   <asp:ListItem Text="No" Value="N"></asp:ListItem>
                   </asp:RadioButtonList>

-----------------

In a confirm box, if I click "ok", the 'Y' item is being selected but if I click "cancel", its not working..
I actually want both the items 'Y' and 'N' to be unchecked on clicking cancel.
anyone please suggest me on this...

Regards
Posted
Comments
Albin Abel 16-Feb-11 3:36am    
on which event the confirm box need to be shown?
Raj.rcr 16-Feb-11 3:46am    
actually I am calling the javascript function "rbtnconfirm()" through C# code..
Raj.rcr 16-Feb-11 4:37am    
Is anybody there? please suggest me on this..

1 solution

Hi Say showing the confirm box on a button click event then...

Here is the example..

I have button
XML
<asp:Button ID="Button2" runat="server" Text="Button" CausesValidation="false"   UseSubmitBehavior="false"/>


Have the javascript in the header section (master page's header)...

XML
<script type="text/javascript">

    function showConfirmBox(id) {
        if (confirm("You want to proceed?")) {
            var ctrl = document.getElementById(id + "_0");
            ctrl.checked = "checked";
        }
        else {
            var ctrl = document.getElementById(id + "_1");
            ctrl.checked = "checked";
        }
    }
</script>


In my page_load event i am assign this script to the button and pass the id of the radio button list to the script...
C#
Button2.Attributes.Add("onclick", "showConfirmBox('" + rbtnDataMatch.ClientID + "')");


thats all. Once the button click it show the confirm box and select the radio button accordingly
 
Share this answer
 
Comments
Raj.rcr 16-Feb-11 6:02am    
is it not possible without using the button?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900