C# 如何在页面刷新后选择单选按钮

C# 如何在页面刷新后选择单选按钮,c#,.net,radio-button,C#,.net,Radio Button,我有一个单选按钮列表,当用户选择一个按钮时,页面会重新加载并显示正确的信息,但按钮不见了 有没有办法避免这种情况 以下是HTML: <div class="checkBoxesColumn"> <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="viewAll" value="0" runat="server" />

我有一个单选按钮列表,当用户选择一个按钮时,页面会重新加载并显示正确的信息,但按钮不见了

有没有办法避免这种情况

以下是HTML:

        <div class="checkBoxesColumn">
            <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="viewAll" value="0" runat="server" />View All</label>
            <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="journey" value="1" runat="server"  />My MBC Journey</label>
            <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="challenges" value="2" runat="server"  />Challenges</label>
            <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="advice" value="3" runat="server"  />Positive Outlooks &amp; Advice</label>
            <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="thanks" value="4" runat="server"  />Giving Thanks</label>
            <label><input class="videoWallRadioCls" name="videoWallRadio" type="radio" id="perspective" value="5" runat="server"  />Family / Friend Perspective</label>
        </div>

查看所有
我的MBC之旅
挑战
积极展望及;忠告
致谢
家庭/朋友视角
下面是背后的代码:

protected void Page_Load(object sender, EventArgs e)
    {
        // HIDE UNTIL 10/13
        if (DateTime.Now > new DateTime(2012, 9, 12))
        {
        mbcRadioList.Visible = true;
        }

    video myVideo = new video();

    string categoryID = "0";
    if (!string.IsNullOrEmpty(Request["category_id"])) categoryID = Request["category_id"];

    Hashtable ht = myVideo.ListingForWall(categoryID);
    //Response.Write("Test: " + ht.Count);
    //Response.Write("Test: " + ht["B-01"]);

    StringBuilder myStringbuilder = new StringBuilder();

    for (int i = 1; i <= 36; i++)
    {
        string iStr = i.ToString();

        if (iStr.Length == 1) iStr = iStr.PadLeft(2, '0');

        //Response.Write("A-" + iStr + "<br />");             
        //Response.Write("TEST: " + ht["A-" + iStr] + "<br />");

        string videoClass = "videoWallThumb thumb" + iStr;

        if (ht["A-" + iStr] != null)
        {
            string[] tmp = ht["A-" + iStr].ToString().Split('|');

            if (tmp[2] == "0") videoClass += " disabled ";

            myStringbuilder.AppendLine("<a class=\"" + videoClass + "\" href=\"videoWallDetail.aspx?video_id=" + tmp[0] + "\"><img src=\"images/video_images/" + tmp[1] + "\" alt=\"\"/></a>");
        }
        else
        {
            videoClass += " incomplete ";
            myStringbuilder.AppendLine("<a class=\"" + videoClass + "\" href=\"#\"><img src=\"images/placeholder.jpg\" alt=\"\"/></a>");
        }

    }

    mosaicA.Text = myStringbuilder.ToString();
}
受保护的无效页面加载(对象发送方,事件参数e)
{
//藏到10月13日
如果(DateTime.Now>newdatetime(2012,9,12))
{
mbcRadioList.Visible=true;
}
video myVideo=新视频();
字符串categoryID=“0”;
如果(!string.IsNullOrEmpty(请求[“类别id”))categoryID=Request[“类别id”];
Hashtable ht=myVideo.ListingForWall(categoryID);
//响应。写入(“测试:+ht.Count”);
//响应。写入(“测试:+ht[“B-01”]);
StringBuilder myStringbuilder=新StringBuilder();

对于(int i=1;i您是否尝试在选中该复选框时设置会话变量?通过这种方式,在页面重新加载时,您可以看到选中了哪一个并将其设置为true

因此,您可以尝试使用单选按钮的Id设置会话变量,当它返回时,您读取该变量并将会话变量保持的Id设置为true

我不确定是否有更好的方法来解决这个问题,但这是我想到的第一件事


我唯一能建议的另一件事是,如果您要使用AJAX调用进行部分更新,这样整个网页就不会重新加载。

您是否尝试过在选中复选框时设置会话变量?这样,在页面重新加载时,您可以看到选中了哪个并将其设置为true

因此,您可以尝试使用单选按钮的Id设置会话变量,当它返回时,您读取该变量并将会话变量保持的Id设置为true

我不确定是否有更好的方法来解决这个问题,但这是我想到的第一件事


我唯一能建议的另一件事是,如果您使用AJAX调用进行部分更新,那么整个网页就不会重新加载。

我认为这是一个ViewState问题。只有web控件才维护ViewState,是什么在回发之间保留了信息

选中此项:

我认为这是一个ViewState问题。只有web控件才维护ViewState,它在回发之间保留信息

选中此项:

没关系,我在分类id上使用了一个开关盒

    switch ((Request["category_id"]))
    {
        case "0": viewAll.Checked = true; break;
        case "1": journey.Checked = true; break;
        case "2": challenges.Checked = true; break;
        case "3": advice.Checked = true; break;
        case "4": thanks.Checked = true; break;
        case "5": perspective.Checked = true; break;
    }

没关系,我在分类号上用了一个开关盒

    switch ((Request["category_id"]))
    {
        case "0": viewAll.Checked = true; break;
        case "1": journey.Checked = true; break;
        case "2": challenges.Checked = true; break;
        case "3": advice.Checked = true; break;
        case "4": thanks.Checked = true; break;
        case "5": perspective.Checked = true; break;
    }