Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i can't provide all the code this is the piece of code where i'm getting the below error;
C#
TextBox tb=new TextBox();
tb.ID="Name";
row.controls.Add(tb);
// here i want check for validation as Mandatory i.e. RequiredFieldValidator 
RequiredFieldValidator rfv1= new RequiredFieldValidator();
rfv1.ControlToValidate="tb";


im getting an error as unable to find the webcontrol "tb" which is defined "ControlToValidate" property of.........

plz any one understands my problem plz help me out
Posted
Updated 20-Oct-11 20:09pm
v2

Try using the Id inside ControlToValidate (instead of the control name itself).
 
Share this answer
 
Comments
sandhya.T 2011 21-Oct-11 1:35am    
i have tried but its giving an error as "web controls are created with in a form tag using runat="server"

but i can't able to write the stmt as
tb.runat="server";
getting a red under the "runat" like(the textbox class cannot have the defined as a method or property)
you are adding textbox control to row but what about requiredFieldValidator?
i think it should also be added. and secondly, as Abhinav said, use textbox id instead of object you created...

C#
row.controls.add(tb);
RequiredFieldValidator rfv1= new RequiredFieldValidator();
row.controls.add(rfv1);
rfv1.ControlToValidate= tb.ID; 
 
Share this answer
 
Comments
sandhya.T 2011 21-Oct-11 2:29am    
yes i have added that after the definition of RFV and ControlTovalidate property stmts

k thanq so much i will check for that one also
and more question??????
how to add the items to DropDownList control at runtime
which one is used DataTextField or else ListItem class object?
sandhya.T 2011 22-Oct-11 1:16am    
i got the control To validate stmt executing but
im getting an error that
"textbox_id of type textbox must be placed in aform tag with runat=server"
sandhya.T 2011 22-Oct-11 1:17am    
Plz help me out of this problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900