ASP.NET的AutoPostBack被清除表单数据 [英] ASP.NET AutoPostBack is clearing form data

查看:215
本文介绍了ASP.NET的AutoPostBack被清除表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单选按钮列表,我想,当用户进行选择来执行一些动作。

I have a radio button list and I want to perform some action when a user makes a selection.

<asp:RadioButtonList id="docList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="loginUser" />

不过,我得到了 docList.SelectedValue 空值。我猜测这是由于在形成自动回数据得到清除。有没有一种方法,我可以有的AutoPostBack 而不失表单数据?

However, I get an empty value for docList.SelectedValue. I am guessing this is due to form data getting cleared upon Autopostback. Is there a way I can have AutoPostBack and not lose form data?

推荐答案

是的,你可以通过这样实现的:

Yes you can by implementing it like this:

<asp:RadioButtonList id="docList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="loginUser" />


public string SelectedDoc {get;set;}
protected void Page_Load(object sender, EventArgs e)
{
   if(!Page.IsPostBack){
   }
   else
   {
      SelectedDoc = docList.SelectedValue; //this will be set on postback and will contain the selected value.
   }
}

这篇关于ASP.NET的AutoPostBack被清除表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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