I have added an onBlur method to an ASP Textbox used for creating a new user logon account. As the user exits the text box I want to take the entered value call a stored procedure to see if that logon value is already used or not.
In the Page_Init of CreateUser.aspx.cs I have the following:
I also have the following method in the cs page:
In the <head> of CreateUser.asxp I have the following, which confirms that it has the value that the user entered:
What do I need to do to get the script to call the ValidateUserLogon method and take the appropriate action once the result gets back to the script?
Steve
In the Page_Init of CreateUser.aspx.cs I have the following:
Code:
txtUserName.Attributes.Add("onBlur", "validateLogon(this)");
I also have the following method in the cs page:
Code:
private void ValidateUserLogon(string cUserLogon)
{
string myConnectionString;
myConnectionString = Utils.GetConnectionString();
SqlConnection conn4 = null;
conn4 = new SqlConnection(myConnectionString);
SqlCommand cmd4 = new SqlCommand("IsLogonUsed", conn4);
cmd4.CommandType = CommandType.StoredProcedure;
cmd4.Parameters.AddWithValue("@LogonValue", SqlDbType.VarChar).Value = txtUserName.Text.Trim();
try
{
conn4.Open();
int ReturnCode = Convert.ToInt32(cmd4.ExecuteScalar());
if (ReturnCode == 1)
{
// This user code is already in use, so force them to enter another value
}
else
{
// This user code is available. Let them continue
}
}
catch (Exception ex)
{
ex = Server.GetLastError();
Server.ClearError();
LogErrorsToSql.Log(ex);
Server.Transfer("~/Errors.aspx");
}
}
In the <head> of CreateUser.asxp I have the following, which confirms that it has the value that the user entered:
Code:
<script type="text/javascript">
function validateLogon(elementRef)
{
var logonValue = document.getElementById('<%=txtUserName.ClientID %>').value;
alert('Entered Values: ' + logonValue);
return true;
}
</script>
What do I need to do to get the script to call the ValidateUserLogon method and take the appropriate action once the result gets back to the script?
Steve