Avatar of tia_kamakshi
tia_kamakshi
Flag for United Arab Emirates asked on

Dynamically added RangeValidatorm not working

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
C#

Avatar of undefined
Last Comment
Pratima

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Pratima

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23