Validating Dynamically Loaded User Controls

B

bremdevnet

I have a ASPX page that loads a custom control. This first custom
control is made up of 2 textboxes and a Submit button. The user enters
data into the form, presses the Submit button and the ASPX page should
either load a new custom control during the postback or (if validation
fails) reload the first custom control. I've attached some validation
controls without a problem but the client-side validation doesn't seem
to be working...even in IE with Javascript enabled.

Does anyone have any suggestions? Thanks!
 
P

Peter Blum

ASP.NET pages expect you to create the same list of controls on post back
that you sent to the browser originally. This allows the post back code
distribute the data to those controls and fire their events (including
Click, TextChanged, and validation). It sounds like you aren't setting
things up the same on each pass.

I recommend this:
Load both UserControls. Change their Visibility. On the first pass,
UserControl 2 should be invisible. On the second pass, during the Click even
method, first test that validation was OK (Page.IsValid=true), then change
the visibility of these Usercontrols.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
G

GreggTB

I don't think that'd work out too well in this case as the first page
(or control view, really) displays a form that prompts the user for
input parameters (i.e., "Select a year", etc.). After postback and
validation, I'd like to use a second control to create a user-specific
report based on the input parameters.

I don't know...maybe I need to rethink the site architecture.
 
S

sam

I'd check the span tag or whatever html is created for the validators
and make sure their controltovalidate ID values match the textbox ID
values. If you are adding controls too late or and setting IDs on them
manually it could screw this up.

Bascially you can debug the validation javascript yourself and see
where its stopping. Its not that hard. Put a breakpoint in
Page_ClientValidate (in WebUIValidation.js in c:\Inetpub\...) and
follow it urself. Also make sure that the call to Page_ClientValidatie
is being executed in the submit button onclick handler or wherever it
is in the html page.

Sorry I don't have exact details but its kindof late :). You can debug
this yourself i've done it many times.

-Sam Robertson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top