User-719153870 posted
Hi NJ2,
First of all, onblur is a front end event, it will call the js method bound to it.
So you will need to define your CheckUser as a JS function rather than a C# one, otherwise it will have no effect.
And you put this event in the page_load, which means that the content of the text box will never change in the method.
And the OnTextChanged
could be a better choice in this scenario indeed, this event is used in the text box, you can refer to this example:
aspx:
<head runat="server">
<title></title>
</head>
<script>
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="userNameTxt" runat="server"
OnTextChanged="userNameTxt_TextChanged"></asp:TextBox>
<asp:Label ID="checkUserName" runat="server" />
</div>
</form>
</body>
cs:
private bool checkUser(String name)
{
if (name != null && !"".Equals(name) )
{
return true;
}
else
{
return false;
}
}
protected void userNameTxt_TextChanged(object sender, EventArgs e)
{
TextBox box = (TextBox)sender;
if (checkUser(box.Text))
{
checkUserName.Text = "username is not empty";
}
else {
checkUserName.Text = "username is empty";
}
}
result:

Best Regard,
Yang Shen