Hello,
In my project , there is a column in the database which is primary key ,the value to this column will be given by user ,
The user should give the "int " value unique ,it should be validated on the client side itself
I have used the following code :
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox3" ErrorMessage="Enter Your Faclty ID" ForeColor="#FF3300" Display="Dynamic">*</asp:RequiredFieldValidator><asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox3" ErrorMessage="Pls Pick Another Number" OnServerValidate="number" ></asp:CustomValidator><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString12 %>" SelectCommand="SELECT [Fid] FROM [Faculties]"></asp:SqlDataSource><asp:Label ID="Label9" runat="server"></asp:Label>
protected void number(object source, ServerValidateEventArgs args) { int fid = Convert.ToInt32(TextBox3.Text); args.IsValid = true; foreach (DataRowView drv in SqlDataSource1.Select(DataSourceSelectArguments.Empty)) { if (drv ["Fid"].ToString() == args.Value.ToString()) { args.IsValid = false; break; } } if (args.IsValid) Label9.Text = "Congratulations! That id is not taken."; }
But it is not working .....
It's urgent could you pls help me out ...