asp.net - C#.Net - RadioButton Control adapter and postback -


I have a radio button control adapter that is used to present the radio button control with the CSS class as part of the input tag Efforts, rather than as a nearby period.

  Public Class Radiabutan Adapter: WebControlEditor {Providing Safe Override Zero (HtmlTextWriter Writer) {RadioButton targetControl = this.Control RadioButton; If (targetControl == faucet) {base.Render (author); Return; } Author. Additional attributes (HtmlTextWriterAttribute.Id, targetControl.ClientID); Author. Additional features (HtmlTextWriterAttribute.Type, "Radio"); Author. Additional Properties (HtmlTextWriterAttribute.Name, targetControl.GroupName); // Bug - Unique group name should be author. AddAttribute (HtmlTextWriterAttribute.Value, targetControl.id); If (targetControl.CssClass.Length> gt; 0) {author. Authorized property (HtmlTextWriterAttribute.Class, targetControl.CssClass); } If (targetControl.Page! = Null) {targetControl.Page.ClientScript.RegisterForEventValidation (targetControl.GroupName, targetControl.ID); } If (targetControl.Checked) {author.AddAttribute (HtmlTextWriterAttribute.Checked, "checked"); } Writer.RenderBeginTag (HtmlTextWriterTag.Input); Writer.RenderEndTag (); }}  

Currently, it is close to what I want, the group name attribute (standard radio button uses the internal value of UniqueGroupName, while I am just using GroupName There can be no way to get unique group names, and the row below can match in any way in this way:

  targetControl.Page.ClientScript.RegisterForEventValidation (targetControl.GroupName , TargetControl.id);  
    value =" radiobuton 1 "name =" ctl00 $ ctl00 $ main contact $ mygroup "/>   New Rendering -  
  Input ID = "ctl00_ctl00_mainContent_RadioButton1" class = "radio" type = "radio" value = ">  

The problem is that postback is not working - RadioButton 1. The check value is always false, the price of the ADO button in the postback?

The reason postbacks are not working is because the return trip was expecting the name ASPNET on the field. Therefore, this is not an ideal solution, but you can use the reflection to get a unique group name:

  Using the system. Reflection; // harvesting ... radiobutan rdb = this Control as RadioButton; String uniqueGroupName = rdb.GetType (). GetProperty ("UniqueGroupName", BindingFlags.Instance | BindingFlags.NonPublic). GETValue (rdb, null) as string;  

Or split into separate rows for clarity:

  type the radio button type = rdb.GetType (); // or typef (radio button) // Get the internal property PropertyInfo uniqueGroupProperty = radioButtonType.GetProperty ("UniqueGroupName", BindingFlags.Instance | BindingFlags.NonPublic); // Receive the value of the property on the current Radioteet object object property Valu = UniqueGroupProperty.GetValue (rdb, null); // as string string, enter string as uniqueGroupName = propertyValue;  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -