问题
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