0

I am having text box, label and button in a repeater control. Button should validate the text box. If the user enter greater than number 4, error message should appear and the text box value should be change based on the label box value.

How to validate the textbox using custom validation inside repeater?

1 Answer 1

0

On OnItemDataBound event OR OnItemCreated event execute this code

 Label lbl = (Label)e.Item.FindControl("lblId"); Button btn = (Button)e.Item.FindControl("btnId"); TextBox txt = (TextBox)e.Item.FindControl("txtId"); CustomValidator cfv = (CustomValidator)e.Item.FindControl("cfvId"); if (cfv != null && txt!=null&&btn!=null&&lblId!=null) { cfv.ControlToValidate = txt.ClientID; cfv.ClientValidationFunction = "YourFunction"; cfv.ValidationGroup = cfv.ClientID + "ValidationGroup"; btn.ValidationGroup = cfv.ClientID + "ValidationGroup"; lbl.AssociatedControlID=txt.ClientID; } //javascript code on client side function YourFunction(sender, args) { args.IsValid=parseInt(args.Value)<=4; if(!args.IsValid) $('#'+sender.controltovalidate).val($('label:[for="'+sender.controltovalidate+'"]').text()); return; } 
Sign up to request clarification or add additional context in comments.

2 Comments

And next action depends from what do you use clear javascript or jquery
With javascript or jquery? Do you define AssociatedControlID property for your label? Can you show aspx code of your template?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.