troubleshooting Question

Dynamically added RangeValidatorm not working

Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates asked on
C#
1 Comment1 Solution213 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros