我正在尝试检查文本框文本更改事件的电子邮件可用性。下面是代码(我从网上捡到的):
HTML (javascript):
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#<%=txtEmailAddress.UniqueID%>").change(function () {
var uname = $("#<%=txtEmailAddress.UniqueID%>");
var msgbox = $("#status");
if (Email.val().length > 0) {
$.ajax({
type: "POST",
url: "SignUp.aspx/usp_CheckEmail",
data: "{'args': '" + Email.val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d == 'Available') {
Email.removeClass("notavailablecss");
Email.addClass("availablecss");
msgbox.html('<img src="Images/a.png"> <font color="Green"> Available </font>');
}
else {
Email.removeClass("availablecss");
Email.addClass("notavailablecss");
msgbox.html(msg.d);
}
}
});
}
else {
Email.addClass("notavailablecss");
msgbox.html('<font color="#cc0000">Email must be unique</font>');
}
});
});
CS:
[System.Web.Services.WebMethod]
protected void txtPassword_TextChanged(object sender, EventArgs e, string args)
{
string returnValue = string.Empty;
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
try
{
SqlCommand sqlCmd = new SqlCommand("usp_CheckEmail", con);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Email", args.Trim());
con.Open();
int success = int.Parse((sqlCmd.ExecuteScalar().ToString()));
if(success == 1) // Email Not Available
{
returnValue = "<img src="Images1/n.png"><font color="#cc0000"><b>'" + args + "'</b> is already in use.</font>"; **//getting syntax error here**
}
else if(success == 0)//Email is available
{
returnValue = "Available";
}
}
catch
{
//Handle Error
}
finally
{
con.Close();
}
return returnValue;
}
}
}
在返回值行中出现错误。什么是正确的语法?此外,它应该显示如下图像:
那么,我的 .aspx 页面上是否需要有图像控件?因为我得到这个代码的文章没有提到有图像控件。如果是的话,我该如何将它们与代码绑定呢?
更新:这是我从http://www.dotnetspark.com/kb/Content.aspx?id=1278获得代码的链接
文章中遗漏了什么?还需要做什么?任何人请..我需要这个...