On my aspx page, I am collecting email addresses from users and making an ajax call like so:
function CheckEmailExistence() {
$.ajax({
url: "Handler.ashx",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { 'Email': $('#txtEmail').val(), 'Method': 'CheckIfEmailExists' },
responseType: "json",
success: HandleCheckEmailExistence,
error: HandleError
});
return false;
}
The code in Handler.ashx.cs executes the following logic after the ajax call is initiated:
case "CheckIfEmailExists":
ss = new Staff();
string Email = context.Request["Email"];
string IsEmailExist = javaScriptSerializer.Serialize(ss.CheckIfEmailExists(Email));
context.Response.ContentType = "text/html";
context.Response.Write(IsEmailExist);
return;
Within the Staff class, this method is called based on the above code:
public int CheckIfEmailExists(string Email)
{
int emailResult = 0;
SQLDatabase sqldb = new SQLDatabase();
DataTable dt = new DataTable();
dt = sqldb.ExecStoredProcedureDataTable("[spDoesEmailExists]", new SQLParamList().Add("@Email", Email));
if (dt.Rows.Count > 1)
{
emailResult = 1;
}
else
{
emailResult = 0;
}
return emailResult;
}
The stored procedure [spDoesEmailExists] simply checks for existing emails in the database:
Select Email from StaffEmailUsage where Email = @Email
It's worth mentioning that there is another function ValidateEmail() for checking email validity.
When a user attempts to use an email address multiple times, they receive a default error message stating:
This email address has been already used!
. Despite trying various troubleshooting methods, errors persist. How can I enforce unique email usage across different users? Any suggestions or guidance would be greatly appreciated. Thank you.