0

Can someone help me with this line of code and tell me what it is looking for? This chunk of code is associated with a text box control on my page.

ValidationGroup="<%# ((TSAPassenger)((RepeaterItem) Container.Parent.Parent).DataItem).PaxKey %>" runat="server" ErrorMessage="Invalid Contact Name.">
Pshemo
  • 122,468
  • 25
  • 185
  • 269
user1566783
  • 399
  • 1
  • 4
  • 18

1 Answers1

2

When a postback occurs (via a button press, autopostback dropdown list, etc), ASP.NET will validate all inputs for the validation group specified on the control that caused the postback.

That line of code is grabbing the 'PaxKey' property of the data item for the repeater item two levels up in the control tree that contains the text box and using it to specify the validation group the textbox belongs to. This is likely there to limit the validation to just the fields for the record you're updating (as opposed to everything on the page).

Luke
  • 477
  • 4
  • 9
  • Ok perfect thanks, so is the only section to really check for that validation is in the part before what i posted in the ValidationExpression="" part? I am just trying to add more validation on to this textbox but it doesnt seem to validate and just skips it so was wondering if this group had code else where or just in the expression? – user1566783 Aug 01 '12 at 15:29
  • It's likely just in the expression, but make sure that any buttons that you want to trigger validation on that textbox have the same value for their ValidationGroup property. – Luke Aug 01 '12 at 15:33
  • Ok great thanks Luke you really have helped out a lot with understanding this. Once more real quick thing since you have a good understanding of this, is I am searching in the text box for people that enter in "test" or "tba" then this validator will catch it. I have tried to just use the ValidationExpression="(test|tba)" will that catch it or do i need something else there? – user1566783 Aug 01 '12 at 15:41
  • Assuming you're using a RegularExpressionValidator with that validation expression, the text will "pass" validation when it matches the condition(s) specified in the expression, and will "fail" when it doesn't match. The expression (test|tba) will match "test" and "tester" but will not match anything that doesn't contain "test" or "tba" – Luke Aug 01 '12 at 15:51
  • Gotcha that is what I am doing wrong it finds those and then sends it through what would be the best practice if I wanted it to fail when it catches test or tba? – user1566783 Aug 01 '12 at 15:56
  • You should be able to use an expression along these lines: ^((?!(test|tba)).)*$ There's a better explanation of this kind of regex pattern in the answers for this question: http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word – Luke Aug 01 '12 at 16:09