[英]Value from row with DropDownList on DropDownList Index Changed Event
[英]Textbox Value disapear when Dropdownlist index changed
我有一个下拉列表和一个TextBox为Password的文本框。 每当dropdownlist索引更改时,文本框的值就会消失。 有人有解决此问题的解决方案吗? 非常感谢。
更新
<asp:DropDownList ID="ddlstudentstatus" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlStudentstatus_SelectedIndexChanged">
</asp:DropDownList>
如果您想在回发时保持文本框内的文本不变,请在page_load中使用以下内容:
if (IsPostBack)
{
if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())))
{
txtPassword.Attributes["value"] = txtPassword.Text;
}
}
发布答案:
我的猜测是下拉列表更改导致回发。 密码不会通过回发保留。
将下拉列表的autopostback值更改为false,将阻止触发SelectedIndexChanged事件。 您可以使用JavaScript或jQuery的hiddenfield来存储密码文本框onblur的值。
$("#txtPassWord").blur(function()
$("#hdnPassWord").val($("#txtPassWord").val());
});
然后,在下拉菜单的SelectedIndexChange事件中,可以从hdnPassWord向txtPassWord赋值。
txtPassWord.Text = hdnPassWord.Value;
如果您没有在SelectedIndexChanged上发回邮件,则意味着没有在服务器端连接事件。 所以要清楚,走哪条路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.