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 423099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:08:48+00:00 2026-05-12T19:08:48+00:00

I have a radio button control adaptor that attempts to render the radio button

  • 0

I have a radio button control adaptor that attempts to render the radio button control with the CSS class as part of the input tag, rather than as a surrounding span.

public class RadioButtonAdapter : WebControlAdapter
{
    protected override void Render(HtmlTextWriter writer)
    {
        RadioButton targetControl = this.Control as RadioButton;

        if (targetControl == null)
        {
            base.Render(writer);

            return;
        }                    

        writer.AddAttribute(HtmlTextWriterAttribute.Id, targetControl.ClientID);
        writer.AddAttribute(HtmlTextWriterAttribute.Type, "radio");        
        writer.AddAttribute(HtmlTextWriterAttribute.Name, targetControl.GroupName); //BUG - should be UniqueGroupName        
        writer.AddAttribute(HtmlTextWriterAttribute.Value, targetControl.ID);
        if (targetControl.CssClass.Length > 0)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, targetControl.CssClass);
        }        

        if (targetControl.Page != null)
        {
            targetControl.Page.ClientScript.RegisterForEventValidation(targetControl.GroupName, targetControl.ID);
        }
        if (targetControl.Checked)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Checked, "checked");
        }            
        writer.RenderBeginTag(HtmlTextWriterTag.Input);
        writer.RenderEndTag();

    }
}

Currently, this renders pretty close to what I want, the only difference being the group name attribute (the standard radio button uses the internal value UniqueGroupName, whereas I am using just GroupName. I can’t seem to find a way to get UniqueGroupName, and the line below should counter this anyway:

targetControl.Page.ClientScript.RegisterForEventValidation(targetControl.GroupName, targetControl.ID);

Old HTML with standard radio buttons-

<span class="radio">
<input id="ctl00_ctl00_mainContent_RadioButton1" type="radio" value="RadioButton1" name="ctl00$ctl00$mainContent$mygroup"/>
</span>

New rendering-

<input id="ctl00_ctl00_mainContent_RadioButton1" class="radio" type="radio" value="RadioButton1" name="mygroup"/>

The problem is that postback is not working – the RadioButton1.Checked value is always false. Any ideas on how to get the radio button’s value in postback?

  • 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-12T19:08:48+00:00Added an answer on May 12, 2026 at 7:08 pm

    The reason postbacks aren’t working is because on the return trip the field name doesn’t match what ASP.NET was expecting. So, it’s not an ideal solution, but you can use reflection to get the UniqueGroupName:

    using System.Reflection;
    
    //snip...
    
    RadioButton rdb = this.Control as RadioButton;
    string uniqueGroupName = rdb.GetType().GetProperty("UniqueGroupName",
        BindingFlags.Instance | BindingFlags.NonPublic).GetValue(rdb, null) as string;
    

    Or broken into separate lines for clarity:

    Type radioButtonType = rdb.GetType(); //or typeof(RadioButton)
    
    //get the internal property
    PropertyInfo uniqueGroupProperty = radioButtonType.GetProperty("UniqueGroupName",
        BindingFlags.Instance | BindingFlags.NonPublic);
    
    //get the value of the property on the current RadioButton object
    object propertyValue = uniqueGroupProperty.GetValue(rdb, null);
    
    //cast as string
    string uniqueGroupName = propertyValue as string;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class ShipmentsCollection that inherits ObservableCollection which contains shipment objects (entities). This
Let's imagine that we have privacy options page in social network; two group of
I have 3 radio buttons on my page. They are loaded by calling a
I have a window with 3 radiobuttons like this(removed all non interesting props): <Control
I have the following scenario. I have a search page which is split into
I am playing with a sample WPF application that is tiered in a Model-View-Presenter
I have the following code which toggles the visibility of one of a pair
I'm using a wizard control, step 1 has a list box with a list
I'm at my wit's end when it comes to this. JavaScript definitely isn't my
I'd like to be able to catch the DoubleClick or MouseDoubleClick events from a

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.