thanks, i tried that, but it didn't work. The validation works, but when the
client side validation runs, it validates the selected value of clientsigned
(radiobuttonlist) instead of the text of the textbox.
note that my composite control is an inherited radioButtonList. Note that
DateBox is a Textbox that adds the validation controls i'm interested in, so
my radiobuttonlist contains a subclassed Textbox which contains some
validators. In the textbox, i set it's validator's controlToValidate
property with the textbox's ID; i'm thinking that somewhere the validator
chooses to use the parent (clientSigned) as its control to validate as
evidence by the rendered html at the bottom.
thanks!
[ValidationPropertyAttribute("DateText")]
public class ClientSigned : DSHS.SNF.Web.Control.RadioButtonList,
DSHS.SNF.Web.Control.IInputControl
{
DSHS.SNF.Web.Control.DateBox dbBox;
DSHS.SNF.Web.Control.Label lblDate;
public ClientSigned()
: base()
{
this.Items.Add(new ListItem("Yes", "Y"));
// add "no" and make it default selected
ListItem no = new ListItem("No", "N");
no.Selected = true;
this.Items.Add(no);
}
public string DateText
{
get { return dbBox.Text; }
set { dbBox.Text = value; }
}
public string dateControlID = string.Empty;
public string DateControlID
{
get { return dateControlID; }
set { dateControlID = value; }
}
protected override void CreateChildControls()
{
base.CreateChildControls();
lblDate = new Label();
lblDate.ID = string.Format("lbl{0}", DateControlID);
lblDate.Text = "Date: ";
dbBox = new DateBox();
dbBox.ID = DateControlID;
dbBox.Columns = 12;
dbBox.ValidatorLabel = ValidatorLabel;
dbBox.IsRequired = IsRequired;
dbBox.ValidationGroup = ValidationGroup;
dbBox.ValidationGroup1 = ValidationGroup1;
Controls.Add(dbBox);
}}
This is the the stuff asp.net rendered for the validator. Notice the
controltovalidate points to the client id of clientsigned instead of the
actual textbox whose client id is:
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_ClientSignatureDate
var
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate = document.all ?
document.all["ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlace
Holder_ClientSigned_DVClientSignatureDate"] :
document.getElementById("ctl00_ctl00_ContentMainPlaceHolder_ApplicationConte
ntMainPlaceHolder_ClientSigned_DVClientSignatureDate");
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate.controltovalidate =
"ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_Client
Signed";
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate.focusOnError = "t";
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate.display = "Dynamic";
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate.evaluationfunction =
"CustomValidatorEvaluateIsValid";
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate.clientvalidationfunction = "ValidateDate";
ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_ClientS
igned_DVClientSignatureDate.validateemptytext = "true";
Steven Cheng said:
Hi TS,
From your description, you've built a custom compostive control(which
contains a textbox), currently, when you use a custom validtor to validate
the Textbox (inside that composite control), you get error indicate the
textbox can not be located, correct?
Based on my understanding, the problem should be caused by the how the
validator control will try locating the "ControlToValidate" control
instance. the Validator controls will only use "ControlToValidate" as ID
and call FindControl at the current Parent namingContainer, below is the
code logic of the BaseValidator(from reflector):
=========================
protected void CheckControlValidationProperty(string name, string
propertyName)
{
Control component = this.NamingContainer.FindControl(name);
if (component == null)
{
throw new HttpException(SR.GetString("Validator_control_not_found",
new object[] { name, propertyName, this.ID }));
}
if (GetValidationProperty(component) == null)
{
throw new HttpException(SR.GetString("Validator_bad_control_type",
new object[] { name, propertyName, this.ID }));
}
}
=========================
Therefore, I'm afraid you can not let validtor control directly locate the
inner textbox nested in your Composite control. For your scenario, I think
you may implement the validation(for the inner TextBox as below):
** Add an dedicated public property on the composite control which expose
the Textbox's "Text" property value
** Apply "ValidationPropertyAttribute" on the composite control and specify
the dedicatd property (defined above) as the validation property.
#ValidationPropertyAttribute Class
http://msdn2.microsoft.com/en-us/library/system.web.ui.validationpropertyatt
ribute(VS.71).aspx
Thus, you can make other validator controls validate against the dedicated
property of the composite so as to validate the value of the inner TextBox.
How do you think?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.