ASP.NET AutoPostBack is clearing form data

ε祈祈猫儿з 提交于 2019-12-24 03:24:50

问题


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" />

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?


回答1:


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.
   }
}


来源:https://stackoverflow.com/questions/10861009/asp-net-autopostback-is-clearing-form-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!