当页面再次回发时,单选按钮未显示 [英] Radio Button not showing checked when page again postback

查看:90
本文介绍了当页面再次回发时,单选按钮未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页项目中,我有一个文本框,按钮,两个radiobuttons和一个texbox的requiredfield验证器。通常,radiobutton1被检查为真,或者如果我选择radiobutton2,它将被检查为真。在按钮上单击页面ll postback,之后没有任何radiobutton被检查。我的radiobuttons UI部分以及当我们clcik在跨度时显示radiobutton



In my web project i have a textbox ,button,two radiobuttons and a requiredfield validator for texbox. Normally the radiobutton1 is checked as true or if i select radiobutton2 it will be checked as true. On button click the page ll postback,after that none of the radiobutton is checked.here is my radiobuttons UI part and also the radiobutton is showed when we clcik on the span

<span class="linktr" data-dialog-append="Form1" data-dialog="detailsPop" data-dialog-width="340" data-dialog-y="center+80 center" data-dialog-x="center center" data-modal="false">Edit</span>

                              <li><strong><asp:RadioButton ID="prRdBtn" runat="server" Text="Private" EnableViewState="True" GroupName="list" CausesValidation="False" /></strong>&nbsp;
                              Only you .
                          </li>
                          <li><strong><asp:RadioButton ID="puRdBtn" runat="server" Text="Public" EnableViewState="True" GroupName="list" CausesValidation="False" /></strong>&nbsp;
                              Anyone can .

推荐答案

您正在代码中的某处设置单选按钮,如果验证失败,可能无法执行。

尝试在其中一个单选按钮中添加Checked =True,以便默认选中它。
You're setting radio buttons somewhere in code which probably doesn't execute if validation fails.
Try adding Checked="True" in one of radio buttons so that it is checked by default.


在您的UI代码中,此处未指定Checked =true RadioButton Control。



如果你在.cs Page_Load事件上指定它,你必须像这样写。



In your UI code, Here you not specify Checked="true" of RadioButton Control.

And if you specify it on .cs Page_Load Event than you have to write it like this.

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack)
        {
            prRdBtn.Checked = true;
        }
}


这篇关于当页面再次回发时,单选按钮未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆