Я пытаюсь проверить, существует ли электронное письмо в базе данных или нет, но каким-то образом событие, похоже, не срабатывает вообще. Я хочу, чтобы, когда кто-то вводил идентификатор электронной почты в текстовое поле и когда он выходил, фокусировал событие servervalidate. должен активировать и подтвердить введенный адрес электронной почты
код Aspx (идентификатор персонализированного идентификатора = "cv3")
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div class="bs-container">
<div class="form-inline required">
<label class="control-label">Name:</label>
<asp:TextBox ID="name" TextMode="SingleLine" CssClass="form-control" placeholder="e.g. John Doe" required="true" runat="server" autofocus="true" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="vendor_cpass" ValidationGroup="vg1" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
<div class="form-inline required">
<label class="control-label">Email:</label>
<asp:TextBox ID="vendor_email" TextMode="Email" CssClass="form-control" CausesValidation="true" placeholder="e.g. me@mymail.com" required="true" runat="server"></asp:TextBox>
<asp:CustomValidator ID="cv3" runat="server" ControlToValidate="vendor_email" Display="Dynamic" Enabled="true" ErrorMessage="Already Exists" ValidationGroup="vg2" OnServerValidate="cv3_ServerValidate"></asp:CustomValidator>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="vendor_email" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ValidationGroup="vg2" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rev1" runat="server" ControlToValidate="vendor_email" ForeColor="Red" Font-Names="verdana" Font-Size="10pt" ValidationGroup="vg2" ValidationExpression="^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" Display = "Dynamic" ErrorMessage = "Invalid email address" SetFocusOnError="true"/>
</div>
<div class="form-inline required">
<label class="control-label">Password:</label>
<asp:TextBox ID="vendor_pass" TextMode="Password" CssClass="form-control" placeholder="Password" CausesValidation="true" required="true" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ValidationGroup="vg3" ControlToValidate="vendor_pass" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rev2" runat="server" ValidationGroup="vg3" ControlToValidate="vendor_pass" ForeColor="Red" Font-Names="verdana" Font-Size="10pt" ValidationExpression="^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$" Display="Dynamic" ErrorMessage="Minimum 8 characters atleast 1 Alphabet, 1 Number and 1 Special Character" SetFocusOnError="true"></asp:RegularExpressionValidator>
</div>
<div class="form-inline required">
<label class="control-label">Confirm Password:</label>
<asp:TextBox ID="vendor_cpass" TextMode="Password" CssClass="form-control" placeholder="Password" required="true" runat="server" CausesValidation="true" ></asp:TextBox>
<asp:CustomValidator ID="cv2" runat="server" ValidationGroup="vg4" ControlToValidate="vendor_cpass" ClientValidationFunction="cp_check" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="" SetFocusOnError="true" EnableClientScript="true"/>
<asp:RequiredFieldValidator ID="rfv4" runat="server" ValidationGroup="vg4" ControlToValidate="vendor_cpass" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
<div class="form-inline required">
<label class="control-label">Mobile No:</label>
<asp:TextBox ID="vendor_mobile" TextMode="Phone" CssClass="form-control" placeholder="e.g. 9999999999" required="true" runat="server" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv5" runat="server" ValidationGroup="vg5" ControlToValidate="vendor_mobile" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rev3" runat="server" ValidationGroup="vg5" ControlToValidate="vendor_mobile" ForeColor="Red" Font-Names="verdana" Font-Size="10pt" ValidationExpression="^\d{10}$" Display="Dynamic" ErrorMessage="Should be 10 digits" SetFocusOnError="true"></asp:RegularExpressionValidator>
</div>
<div class="form-inline required">
<label>Address</label>
<br />
<label class="control-label">Street Address:</label>
<asp:TextBox ID="street" TextMode="SingleLine" CssClass="form-control" placeholder="e.g. 7th Avenue Street" required="true" runat="server" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv6" runat="server" ValidationGroup="vg6" ControlToValidate="street" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<br />
<label class="control-label">City:</label>
<asp:TextBox ID="city" TextMode="SingleLine" CssClass="form-control" placeholder="e.g. Kolkata" required="true" runat="server" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv7" runat="server" ValidationGroup="vg6" ControlToValidate="city" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<br />
<label class="control-label">State:</label>
<asp:TextBox ID="state" TextMode="SingleLine" CssClass="form-control" placeholder="e.g. West Bengal" required="true" runat="server" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv8" runat="server" ValidationGroup="vg6" ControlToValidate="state" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<br />
<label class="control-label">Pincode:</label>
<asp:TextBox ID="pincode" TextMode="SingleLine" CssClass="form-control" placeholder="e.g. 700700" required="true" runat="server" CausesValidation="true"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv9" runat="server" ValidationGroup="vg6" ControlToValidate="pincode" Display="Dynamic" ForeColor="red" Font-Names="verdana" Font-Size="10pt" ErrorMessage="Required" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rev4" runat="server" ValidationGroup="vg6" ControlToValidate="pincode" ForeColor="Red" Font-Names="verdana" Font-Size="10pt" ValidationExpression="^\d{6}$" Display="Dynamic" ErrorMessage="Should be 6 digits" SetFocusOnError="true"></asp:RegularExpressionValidator>
</div>
<div class="form-inline required">
<label>Criteria for email notification</label>
<br />
<label>Estimated cost of project</label>
<asp:DropDownList runat="server" ID="ecp" CssClass="form-control">
<asp:ListItem Text="--Any Amount--" Value="0" Selected="True"></asp:ListItem>
<asp:ListItem Text="1 Lakh and Above" Value="1"></asp:ListItem>
<asp:ListItem Text="5 Lakhs and Above" Value="5"></asp:ListItem>
<asp:ListItem Text="10 Lakhs and Above" Value="10"></asp:ListItem>
<asp:ListItem Text="50 Lakhs and Above" Value="50"></asp:ListItem>
<asp:ListItem Text="1 Crore and Above" Value="100"></asp:ListItem>
<asp:ListItem Text="5 Crores and Above" Value="500"></asp:ListItem>
<asp:ListItem Text="10 Crores and Above" Value="1000"></asp:ListItem>
<asp:ListItem Text="50 Crores and Above" Value="5000"></asp:ListItem>
</asp:DropDownList>
<br />
<label class="control-label">Please Select the Subjects for which Tender notices you are Interested</label>
<asp:CheckBox ID="main_check" Checked="true" Text="Notify me for all tenders" runat="server" Onclick="main_check_changed(this)" />
<br />
<label>Goods</label>
<br />
<asp:CheckBoxList ID="goods" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"></asp:CheckBoxList>
<br />
<label>Services</label>
<asp:CheckBoxList ID="services" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"></asp:CheckBoxList>
</div>
<div class="form-inline required">
<asp:Button ID="submit" runat="server" Text="Submit" Width="81px" OnClick="submit_Click" CausesValidation="true" />
<asp:Button ID="reset" runat="server" Text="Reset" Width="81px" OnClientClick="this.form.reset();return false;" />
</div>
</div>
C# код: (метод cv3_ServerValidate)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;
namespace Tender
{
public partial class vendor_reg : System.Web.UI.Page
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string v_id;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from goods");
cmd.Connection = con;
MySqlDataReader sdr = cmd.ExecuteReader();
goods.DataSource = sdr;
goods.DataTextField = "title";
goods.DataValueField = "goods_id";
goods.DataBind();
for (int i = 0; i < goods.Items.Count; i++)
{
goods.Items[i].Selected = true;
goods.Items[i].Attributes.Add("onclick", "checkedchanged(this)");
}
con.Close();
con.Open();
MySqlCommand cmd1 = new MySqlCommand("select * from services");
cmd1.Connection = con;
MySqlDataReader sdr1 = cmd1.ExecuteReader();
services.DataSource = sdr1;
services.DataTextField = "title";
services.DataValueField = "service_id";
services.DataBind();
for (int i = 0; i < services.Items.Count; i++)
{
services.Items[i].Selected = true;
services.Items[i].Attributes.Add("onclick", "checkedchanged(this)");
}
}
}
public void MsgBox(String ex, Page pg, Object obj)
{
string s = "<SCRIPT language='javascript'>alert('" + ex.Replace("\r\n", "\\n").Replace("'", "") + "'); </SCRIPT>";
Type cstype = obj.GetType();
ClientScriptManager cs = pg.ClientScript;
cs.RegisterClientScriptBlock(cstype, s, s.ToString());
}
protected void cv3_ServerValidate(object source, ServerValidateEventArgs args)
{
MsgBox("! your message !", this.Page, this);
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select vendor_id from vendor where vendor_email=@email;");
cmd.Parameters.AddWithValue("@email", vendor_email.Text);
cmd.Connection = con;
MySqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
cv3.ErrorMessage = "Email already exists in our database.Please check or try to login";
args.IsValid = false;
}
else
{
args.IsValid = true;
}
con.Close();
}
protected void submit_Click(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("Insert into vendor (vendor_email,vendor_pass,vendor_name,vendor_addr,vendor_phone,vendor_ecp) values(@email, Aes_Encrypt(@pass,@email), @name, @addr, @phone, @ecp)", con);
String addr = street.Text + ", " + city.Text + ", " + state.Text + ", " + pincode.Text;
cmd.Parameters.AddWithValue("@email", vendor_email.Text);
cmd.Parameters.AddWithValue("@pass", vendor_pass.Text);
cmd.Parameters.AddWithValue("@name", name.Text);
cmd.Parameters.AddWithValue("@addr", addr);
cmd.Parameters.AddWithValue("@phone", vendor_mobile.Text);
cmd.Parameters.AddWithValue("@ecp", ecp.SelectedValue);
cmd.ExecuteNonQuery();
cmd.Dispose();
MySqlCommand cmd1 = new MySqlCommand("select vendor_id from vendor where vendor_email=@email;");
cmd1.Parameters.AddWithValue("@email", vendor_email.Text);
cmd1.Connection = con;
MySqlDataReader sdr1 = cmd1.ExecuteReader();
if (sdr1.Read()) {
v_id = sdr1[0].ToString();
}
cmd1.Dispose();
MySqlCommand cmd2 = new MySqlCommand("insert into vendor_goods (vendor_id,goods_id) values(@v_id, @g_id)", con);
MySqlCommand cmd3 = new MySqlCommand("insert into vendor_services (vendor_id,service_id) values(@v_id, @s_id)", con);
for(int i = 0; i < goods.Items.Count; i++)
{
if (goods.Items[i].Selected == true)
{
cmd2.Parameters.Clear();
cmd2.Parameters.AddWithValue("@v_id", v_id);
cmd2.Parameters.AddWithValue("@g_id", goods.Items[i].Value);
cmd2.ExecuteNonQuery();
}
}
for (int i = 0; i < services.Items.Count; i++)
{
if (services.Items[i].Selected == true)
{
cmd3.Parameters.Clear();
cmd3.Parameters.AddWithValue("@v_id", v_id);
cmd3.Parameters.AddWithValue("@s_id", services.Items[i].Value);
cmd3.ExecuteNonQuery();
}
}
con.Close();
Response.Redirect("vendor_login.aspx");
}
}
}