Monday, 8 July 2013

How to show confirm box on radio button list item change in asp.net

How to show confirm box on radio button list item change in asp.net?
How to show confirm box on radio button list item change in asp.net when autopostback is set to true?

Step-1:

Create Your Radibutton List Item

<asp:RadioButtonList ID="List1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="List1_Changed" RepeatDirection="Horizontal"
        <asp:ListItem onclick="return CheckValue(this);">X</asp:ListItem>
        <asp:ListItem onclick="return CheckValue(this);">Y</asp:ListItem>

    </asp:RadioButtonList>

Step-2:
Write Your javascript Code

function CheckValue(item)
{
    if(confirm('Are You Sure To Change The Item?'))
     setTimeout('__doPostBack(\'' + item.id + '\',\'' + item.value + '\')', 0);
else
 return false;
}

Step-3:

Your Code Behind will be

protected void List1_Changed(object sender, EventArgs e) {
           //Write your stuffzzzz

        }
Demo In Html:-
Please Select Any One
A
B
C

No comments:

Post a Comment