Dynamically added RangeValidatorm not working

tia_kamakshi
tia_kamakshi used Ask the Experts™
on
Hi,

I am working in asp.net using c#

I have added RangeValidator dynamically, but it is not working. Can you please help me whay my dynamic validator is not working

I have added textbox and validator dynamically and I can see dynamic textbox on my screen from below code

hcell = new HtmlTableCell();
hcell.VAlign = "top";
TextBox txtUnitCost = new TextBox();
txtUnitCost.ID = "txtUnitCost" + Convert.ToString(cnt);
txtUnitCost.CssClass = "formTextTender";


RangeValidator rgvUnitCost = new RangeValidator();
rgvUnitCost.ValidationGroup = "tenderSubmit";
rgvUnitCost.ID = "rgvUnitCost" + Convert.ToString(cnt);
rgvUnitCost.Type = ValidationDataType.Double;
rgvUnitCost.ControlToValidate = "txtUnitCost" + Convert.ToString(cnt);
rgvUnitCost.ErrorMessage = "Please enter valid unit cost " + Convert.ToString(cnt);
rgvUnitCost.Display = ValidatorDisplay.None;
rgvUnitCost.SetFocusOnError = true;
rgvUnitCost.Visible = true;
rgvUnitCost.EnableClientScript = true;
rgvUnitCost.Enabled = true;

hcell.Controls.Add(txtUnitCost);
hcell.Controls.Add(rgvUnitCost);

hrow.Cells.Add(hcell);  



Below is the text field whose validator works and this is not dynamic

<asp:TextBox ID="txtAddress1" runat="server" CssClass="formText"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtAddress1"
                    ErrorMessage="Address1 field cannot be blank" ValidationGroup="tenderSubmit" Display="None" SetFocusOnError="True"></asp:RequiredFieldValidator></td>


Below is my validator summary added in aspx page      
       
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
            HeaderText="You must enter a value in the following fields:" ShowMessageBox="True"
            ShowSummary="False" ValidationGroup="tenderSubmit" />
           
           
Please guide
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I tried like this properties it works

            rgvUnitCost.ID = "rgvUnitCost" + Convert.ToString(cnt);
                  rgvUnitCost.Type = ValidationDataType.Double;
                  rgvUnitCost.MaximumValue = "20.0";
                  rgvUnitCost.MinimumValue = "11.0";
                  rgvUnitCost.ControlToValidate = "txtUnitCost" + Convert.ToString(cnt);
                  rgvUnitCost.ErrorMessage = "Please enter valid unit cost " + Convert.ToString(cnt);
                              rgvUnitCost.Visible = true;
                  rgvUnitCost.EnableClientScript = true;
                  rgvUnitCost.Enabled = true;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial