RadioButtonList SelectedIndex 不变
我有简单的单选按钮列表,其中包含我从不更改的静态 ListItems。当用户选择单选按钮并按下提交按钮时,所选索引将返回到-1。我没有使用任何 UpdatePanels,我没有对 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);
}
}
i have simple radio button list, with static ListItems which i never change. When user selects radio and press submit button, selected index is back to -1. I am not using any UpdatePanels, i havent changed anything with ViewState (i tried both: enabled and disabled), i have tried AutoEventWireup true and false, all values are unique. Nothing helps.
Page code:
<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>
Page codebehind:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
杀死 Page_init 中的
OnClick="OnUserCreate"
设置处理程序,例如
UserCreateButton.click += new System.EventHandler(OnUserCreate);
Kill the
OnClick="OnUserCreate"
set handler in Page_init like
UserCreateButton.click += new System.EventHandler(OnUserCreate);