页面奇怪的行为
我在我的页面上遇到了如此奇怪的动作。
我有一个单选按钮列表,根据我的选择执行特定的代码。
问题是:
例如,当我选择选项 2
时,我选择返回选项 1
。
页面保持状态(所有下拉列表保持之前的选择),我需要再次单击链接以强制页面进入此状态:
if (!Page.IsPostBack)
{
BindCamp(0);
BindCamp(1);
}
my aspx :
<asp:RadioButtonList ID="rbl" runat="server"
OnSelectedIndexChanged="rbl_SelectedIndexChanged"
RepeatDirection="Horizontal" Width="200px" AutoPostBack="True">
<asp:ListItem Value="0" Selected="True">view data</asp:ListItem>
<asp:ListItem Value="1">view report</asp:ListItem>
</asp:RadioButtonList>
My code :
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbl.SelectedItem.Value == "0")
{
pnl_view.Visible = true;
pnl_stat.Visible = false;
pnl_rep.Visible = false;
}
else
{
pnl_view.Visible = false;
pnl_all.Visible = false;
pnl_Dean.Visible = false;
pnl_research.Visible = false;
pnl_stat.Visible = true;
}
}
I face so strange action in my page.
I have a radio button list, according to the selection i execute specific code.
The problem is:
for example when i select option 2
then i select back option 1
.
the page maintains the state(all the drop down lists maintain their previous selections) and i need to click the link one more time to force the page to enter this condition:
if (!Page.IsPostBack)
{
BindCamp(0);
BindCamp(1);
}
my aspx :
<asp:RadioButtonList ID="rbl" runat="server"
OnSelectedIndexChanged="rbl_SelectedIndexChanged"
RepeatDirection="Horizontal" Width="200px" AutoPostBack="True">
<asp:ListItem Value="0" Selected="True">view data</asp:ListItem>
<asp:ListItem Value="1">view report</asp:ListItem>
</asp:RadioButtonList>
My code:
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbl.SelectedItem.Value == "0")
{
pnl_view.Visible = true;
pnl_stat.Visible = false;
pnl_rep.Visible = false;
}
else
{
pnl_view.Visible = false;
pnl_all.Visible = false;
pnl_Dean.Visible = false;
pnl_research.Visible = false;
pnl_stat.Visible = true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论,DLL 将始终保留它们的值,除非您手动设置选择,您设置 EnableViewState="false" (然后禁用所有视图状态)。所以我认为您可能需要执行以下操作的代码:
单击下一个单选按钮时。
Per your comments, DLL's will always retain their values unless you manually set the selection, you set EnableViewState="false" (which disabled all viewstate then). So I think you may need code that does:
Upon clicking the next radio button.