Greetings,
I have a grid in which I am doing some RequiredField validations. I also have a single CustomValidator that tests if the specific value already exists in my DB. I only want the custom validation to happen when I am inserting new records. How do I check in my ServerValidation method, which state the grid is in. i am still learning this stuff so please be patient with me.
Here is the the grid column that I am trying to validate.
and the Validation in the code-behind
I'd be grateful for any assistance. Thanks
I have a grid in which I am doing some RequiredField validations. I also have a single CustomValidator that tests if the specific value already exists in my DB. I only want the custom validation to happen when I am inserting new records. How do I check in my ServerValidation method, which state the grid is in. i am still learning this stuff so please be patient with me.
Here is the the grid column that I am trying to validate.
| <telerik:GridTemplateColumn DataField="EID" HeaderText="EID" UniqueName="EID"> |
| <ItemTemplate> |
| <asp:Label runat="server" ID="lblEID" Text='<%# Eval("EID", "{0}") %>'></asp:Label> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadTextBox runat="server" ID="tbEID" Skin="Office2007" Width="158" |
| Text='<%# DataBinder.Eval(Container, "DataItem.EID") %>'> |
| </telerik:RadTextBox> |
| <span style="color: Red">*</span> |
| <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbEID" |
| ErrorMessage="EID is required" runat="server"></asp:RequiredFieldValidator> |
| <asp:CustomValidator ID="EIDValidator" ControlToValidate="tbEID" OnServerValidate="CheckEID" |
| ErrorMessage="This user already exists" runat="server"></asp:CustomValidator> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
and the Validation in the code-behind
| protected void CheckEID(object source, ServerValidateEventArgs args) |
| { |
| DataSet ds = new DataSet(); |
| SqlParameter[] param = new SqlParameter[1]; |
| param[0] = ExpertProvider.SqlDB.MakeParameter("@EID", args.Value); |
| ExpertProvider.SqlDB.RunProcedure("Database.Expert.ConnectionString", |
| "HSOExpertSystem_Admin_Users_Get_User", param, ref ds); |
| if (ds.Tables[0].Rows.Count > 0) |
| { |
| args.IsValid = false; |
| } |
| else |
| { |
| args.IsValid = true; |
| } |
| } |
I'd be grateful for any assistance. Thanks
