By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,414 Members | 2,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,414 IT Pros & Developers. It's quick & easy.

Validation in User Controls used with Master Pages

P: n/a
In my ASP.NET 2.0 web app, I have a user control, ucBinEdges, with several
text boxes. The user control has several validation controls validating the
Text of these text boxes - CompareValidator, RangeValidator,
RequiredFieldValidator, and a ValidationSummary. The page using ucBinEdges
is a content page working in conjunction with a master page. The master page
defines two ContentPlaceHolders: cphLeftNav and cphReportContent. ucBinEdges
is placed in cphLeftNav. The other content area, cphReportContent, contains
a bunch of other ASP.NET controls.

There are several problems:

1. After adding the validation controls to ucBinEdges, the contents of
cphReportContent do not render to the browser. However, if I add
EnableClientScript="false" to each of the validation controls, everything
displays correctly. Of course, now the validation does not occur
client-side, but only on a postback.

2. Living with only server-side validation for the moment, the validation
occurs *after* the user control Page_Load and TextBox TextChanged event
handlers are fired. This means that code which depends on valid values blows
up. For example, the following line raises an exception if the the Text
property is "abc":
AmountBinMin = Convert.ToInt32(txtMin.Text)

3. OK, so I wrapped the potentially offending lines in a try block, an
inelegant hack at best. Now the validation works fine. Except I am back to
the problem where the contents of cphReportContent do not display when the
page posts back.

4. Finally, if the user corrects the invalid value in the text box and
clicks on a button in cphLeftNav, the following exception is raised:
Invalid postback or callback argument. ... blah blah blah ... use the
ClientScriptManager.RegistserForEventValidation method in order to register
the postback or callback for data validation.

Anybody know what is going on here? It seems the best solution would be to
get the client-side validation working. Failing that, I will probably have
to remove the validation controls entirely and do the data validation myself.

Thanks for any suggestions.

Sep 8 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.