c# - Can't Add RegularExpressionValidator to Panel -


i'm having issue programmatically adding regularexpressionvalidator container control (panel, placeholder, etc.). here code:

// path of file on server string page = page.request.filepath; int managementcompanyid = convert.toint32(session["managementcompanyid_addresident"].tostring().trim());  // field validation details collection<exportfieldvalidation> details = validationbl.getvalidationdetails(managementcompanyid, page);  contentplaceholder body = page.form.findcontrol("contentbody") contentplaceholder;  foreach (exportfieldvalidation detailitem in details) {     // check if control exists on page     textbox control = body.findcontrol(detailitem.fieldtovalidate) textbox;      if (control != null)     {         regularexpressionvalidator regex = new regularexpressionvalidator()         {             controltovalidate = control.uniqueid.tostring(),             id = detailitem.validatorfieldname,             validationexpression = detailitem.regularexpression,             page = this,             setfocusonerror = true,             text = detailitem.errormessage,             enabled = true,             enableviewstate = true,             cssclass = "error"         };          panel validationpanel = body.findcontrol("paneladdresident") panel;          validationpanel.controls.add(regex);     } } 

when go page error unable find control id 'mycontrol' referenced 'controltovalidate' property of 'regularexpressionvalidatorresidentid', control control.uniqueid.tostring() above, store in database , sure correct, i've double-, triple- , quadruple-checked value.

however, if replace validationpanel.controls.add(regex); page.form.controls.add(regex); works perfectly.

is there way add validator container? i'm sure i'm doing wrong or missing step in middle somewhere. appreciated.

this part wrong:

controltovalidate = control.uniqueid.tostring() 

you need use this:

controltovalidate = control.id; 

you must provide id control before. uniqueid name component have in client validator controls use server side control name this.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -