【问题标题】:RadioButtonList SelectedIndex not changingRadioButtonList SelectedIndex 没有改变
【发布时间】:2011-12-12 11:24:00
【问题描述】:

我有简单的单选按钮列表,带有我从不更改的静态 ListItems。当用户选择单选并按下提交按钮时,所选索引返回-1。我没有使用任何 UpdatePanel,我没有使用 ViewState 更改任何内容(我尝试了:启用和禁用),我尝试了 AutoEventWireup true 和 false,所有值都是唯一的。没有任何帮助。

页面代码:

<div class="content">
    <div id="registration">
        <asp:Literal runat="server" ID="Literal1" Text="Registration" />
        <asp:Panel runat="server" DefaultButton="UserCreateButton">
            <table class="registration_table">
                <tr><td>
                    <asp:Literal ID="NameLiteral" runat="server" Text='<%$ Resources: Resource, LabelName %>' />
                </td><td>
                    <asp:TextBox runat="server" ID="NameTextBox" autocomplete="off" />
                </td></tr>
                <tr><td>
                    <asp:Literal ID="SurnameLiteral" runat="server" Text='<%$ Resources: Resource, LabelSurame %>' />
                </td><td>
                    <asp:TextBox runat="server" ID="SurnameTextBox" autocomplete="off" />
                </td></tr>
                <tr><td>
                    <asp:Literal ID="UsernameLiteral" runat="server" Text='<%$ Resources: Resource, LabelUsername %>' />
                </td><td>
                    <asp:TextBox runat="server" ID="UsernameTextBox" autocomplete="off" />
                </td></tr>
                <tr><td>
                    <asp:Literal ID="PasswordLiteral" runat="server" Text='<%$ Resources: Resource, LabelPassword %>' />
                </td><td>
                    <asp:TextBox runat="server" ID="PasswordTextBox" TextMode="Password" autocomplete="off" />
                </td></tr>
                <tr><td>
                    <asp:Literal ID="SexLiteral" runat="server" Text='<%$ Resources: Resource, LabelSex %>' />
                </td><td>
                    <asp:RadioButtonList ID="SexList" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Text="Not chosen" Value="0" Selected="True" />
                        <asp:ListItem Text="Male" Value="1" />
                        <asp:ListItem Text="Female" Value="2" />
                    </asp:RadioButtonList>
                </td></tr>
            </table>
            <asp:Button runat="server" ID="UserCreateButton" Text='<%$ Resources: Resource, LabelRegister %>' OnClick="OnUserCreate" />
        </asp:Panel>
    </div>
</div>

页面代码隐藏:

public new UserCreatePresenter Presenter
{
    get { return base.Presenter as UserCreatePresenter; }
    set { base.Presenter = value; }
}

protected void Page_Load(object sender, EventArgs e)
{
}

public void OnUserCreate(object sender, EventArgs e)
{
    if (Presenter != null)
    {
        Presenter.OnUserCreate(
            NameTextBox.Text,
            SurnameTextBox.Text,
            UsernameTextBox.Text,
            PasswordTextBox.Text,
            SexList.SelectedValue);
    }
}

【问题讨论】:

  • 你是在PageLoad中绑定RadioButtonList还是Page?
  • 我们可以看看你的其余代码吗?
  • 我没有在 PageLoad 或 PreInit 中做任何事情
  • 请编辑您的问题并在页面内发布一些代码
  • 我添加了更多代码。对于演示者 SelectedValue 总是等于 0。

标签: asp.net postback radiobuttonlist


【解决方案1】:

杀死OnClick="OnUserCreate"

在 Page_init 中设置处理程序,例如 UserCreateButton.click += new System.EventHandler(OnUserCreate);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2011-01-03
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 2017-02-16
    相关资源
    最近更新 更多