我有这个UpdatePanel
:
<asp:ScriptManager ID="CheckManager" runat="server" />
<asp:UpdatePanel ID="checkUsername" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="canUse" runat="server" Text=""/>
<asp:Button ID="check" runat="server" Text="Usable?" onclick="check_Click" />
<asp:TextBox ID="username" runat="server" ></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger controlid="check" eventname="Click" />
</Triggers>
</asp:UpdatePanel>
更新代码:
protected void check_Click(object sender, EventArgs e)
{
using (HotelEntities h = new HotelEntities())
{
UserHandle u = new UserHandle();
if (u.FindUserByUsername(h, username.Text.ToString()).Any())
{
canUse.ForeColor = Color.Magenta;
canUse.Text = "You cannot use this username";
username.Text = "";
}
else
{
canUse.ForeColor = Color.Green;
canUse.Text = "you can use this username";
}
}
}
但仅当表单中的其他输入(例如具有验证RequiredFieldValidator
)有效时才有效。
我怎样才能解决这个问题?