-1

ラジオボタンをgroupnameプロパティと一緒にグループ化しようとしています。レンダリング中のasp.netの命名規則のため、機能しません。

そのため、ラジオボタンコントロールを継承し、ラジオボタンをオーバーライドして、独自のコントロールを作成しようとしました。

グループ化の問題は解決しましたが、何らかの理由でビューステートを処理していません...したがって、すべてのラジオボタンはビューステートがありません。

これが私のコードです:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace CustomControl
{
    public class GroupRadioButton : RadioButton
    {
        public GroupRadioButton()
            : base()
        { }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(new GroupedRadioButtonTextWriter(writer,this.GroupName));
        }
    }

    public class GroupedRadioButtonTextWriter : HtmlTextWriter
    {
        private string groupName;

        public GroupedRadioButtonTextWriter(HtmlTextWriter baseWriter, string groupName) : base(baseWriter)
        {
            this.groupName = groupName;
        }

        public override void AddAttribute(HtmlTextWriterAttribute key, string value)
        {
            if (key == HtmlTextWriterAttribute.Name)
            {
                base.AddAttribute(key, this.groupName);
            }
            else
            {
                base.AddAttribute(key, value);
            }
        }
    }
}

誰か助けてもらえますか?

4

1 に答える 1