Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:48:19+00:00 2026-05-23T09:48:19+00:00

I have a RadioButtonList with 2 items. I want a postback when any of

  • 0

I have a RadioButtonList with 2 items. I want a postback when any of the items is selected. I have added a confirm box for one item of RadioButtonList. But, when I click OK in the confirmbox, there is no postback and SelectedIndexChanged event is not getting fired.

AutoPostback property of RadioButtonList is set to true.
This is a code fragment from my Page_Load method:

RadioButtonOpenRestricted.Attributes.Add("AutoPostBack", "True");
RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("AutoPostBack", "True");
RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("OnClick", "javascript:return confirm('Are you sure?');");

Earlier, I had added confirm box for entire RadioButtonList and postback was working as expected. But I want the confirm box to be displayed only when user clicks on “Open Access” item.

Please help!


I tried a few things. The new code lines look like:

RadioButtonOpenRestricted.Items.FindByValue(“Open Access”).Attributes.Add(“OnClick”, “javascript:showConfirmBox(0,'” + RadioButtonOpenRestricted.ClientID + “‘)”);
RadioButtonOpenRestricted.Items.FindByValue(“Restricted Access”).Attributes.Add(“OnClick”, “javascript:showConfirmBox(1,'” + RadioButtonOpenRestricted.ClientID + “‘)”);

The javascript method is:

function showConfirmBox(i,id)
{
if(i==0)
{
if (confirm(“Are you sure you want to provide Open Access? All existing individual permissions will be removed!”)==true)
{
var ctrl1 = document.getElementById(id + “_0”);
ctrl1.selected=true;
}
else
{
var ctrl2 = document.getElementById(id + “_1”);
ctrl2.selected=true;
}
}
if(i==1)
{
var ctrl2 = document.getElementById(id + “_1”);
ctrl2.selected=true;
}
}

The problem with this code is that it is treating both OK and Cancel as same. The confirm box is getting displayed but if-else part of the javascript method is not getting called. I tried using OnClientClick also…this doesnt even display the Confirmbox.

Help!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:48:20+00:00Added an answer on May 23, 2026 at 9:48 am

    This is because your on click script does not play well with auto-post back script generated by the ASP.NET. A quick hack solution can be

    RadioButtonOpenRestricted.AutoPostBack = true;
    RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("OnClick", "if (!confirm('Are you sure?')) return false;");
    

    Although, this will still give you an issue when you cancel on your confirmation box (in such case, you have to add script to select the previous radio button again).

    As such I am not a great fan of radio button list – you may consider alternate mechanism such as repeater with radio button in item template and having your own java-script for confirmation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table cell with a RadioButtonList . When each item is selected,
I have a radiobuttonlist; when item[1] is clicked a textbox is displayed and my
I have a RadioButtonList control and I would like to do a Javascript confirm
I have this code: <asp:RadioButtonList ID=rblExpDate runat=server > <asp:ListItem Selected=True Text=No expiration date></asp:ListItem> <asp:ListItem
I have an asp:RadioButtonList and want to declaratively bind the value to an enumeration.
I have a RadioButtonList which contain 4 radio buttons A,B,C,D RBQ.Items.Add("A") RBQ.Items.Add("B") RBQ.Items.Add("C") RBQ.Items.Add("D")
I have a page that add Items to RadioButtonList with this code : Protected
I have a RadioButtonList in an UpdatePanel. Say I click the second button (value
I have two radiobuttonlist and one checkboxlist on the page. Ideally based on the
i have a asp:radio button with two list items asp:RadioButtonList id=Myradio asp:listitem1 value=li1 asp:listitem2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.