【发布时间】:2016-02-17 09:53:12
【问题描述】:
我有电子邮件字段和标签
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:TextBox runat="server" ID="txtUserEmail" onfocusout="emailVerification()" CssClass="forTextbox ui-corner-all" PlaceHolder="Enter your email"></asp:TextBox>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:ScriptManager runat="server" ID="smForEmail"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="upLblEmail">
<ContentTemplate>
<asp:Label runat="server" ID="lblEmail"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
</asp:TableRow>
还有其他一些领域。
我想当用户移动到下一个字段时调用onfocusout="emailVerification()" 方法。在这种方法中,我想检查数据库中是否存在电子邮件。为此,我编写了存储过程。
USE [CDistributors]
GO
/****** Object: StoredProcedure [dbo].[sp_InsertUser] Script Date: 2/17/2016 2:50:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_InsertUser]
(@Email varchar(50) = null,
@ReturnValue int = null)
As
Begin
SET NOCOUNT ON;
IF EXISTS (SELECT UserId from Users where Email = @Email)
Begin
return 0; -- Email already registered
End
Else
Begin
return 1; -- Email is not registered yet
End
End
而JavaScript函数是
// code for email verification
$(function () {
function emailVerification() {
// What code to call stored procedure that return integer
}
});
请帮忙。
【问题讨论】:
-
这是个非常糟糕的主意。您应该制作服务器端 POST/GET 验证方法并从 javascript 询问此方法。
标签: javascript c# jquery stored-procedures webforms