asp.net - Duplicate values in multiple textbox -
how validate whether text in multiple textboxes unique each other.
it looks in asp.net not valid syntax
bool hasnoduplicate = (txtemergencyname1.text.trim() <> txtemergencyname2.text.trim() <> txtemergencyname3.text.trim <> txtemergencyname4.text.trim); i looking efficient appraoch, kind of lamda look or inbuilt in asp.net
since you're asking lambda, here's linq approach.
var alltxt = new[] { txtemergencyname1, txtemergencyname2, txtemergencyname3, txtemergencyname4 }; var alltext = alltxt.select((txt, i) => new { text = txt.text.trim(), pos = + 1 }).tolist(); bool hasnoduplicate = !alltext.any(t => alltext.skip(t.pos).any(t2 => t.text == t2.text)); put relevant textboxes in collection array , utilize enumerable.any. skipping before current textbox avoid checking textboxes twice.
if relevant textboxes in container command panel, utilize enumerable.oftype find them:
ienumerable<textbox> alltxt = this.emergencypanel.controls.oftype<textbox>(); side-note: it's premature optimization anyway performant way validate controls. nil doing , there never millions of controls. instead should shortest or readable approach.
asp.net performance duplicates
No comments:
Post a Comment