Last post Jan 14, 2008 12:07 AM by Nai-Dong Jin - MSFT
Jan 10, 2008 10:37 PM|Natural Cause|LINK
I'm trying to create a custom web control which i can get working but i can't get the properties....
public class TextBoxEmail : WebControl, INamingContainer
TextBox textBox = new TextBox();
private bool _validateField;
public string Text
public bool ValidateField
_validateField = value;
textBox.ID = "InputField";
Email emailValidator = new Email();
emailValidator.ControlToValidate = textBox.ID;
emailValidator.ID = "EmailValidation";
emailValidator.ErrorMessage = "Invalid Email";
emailValidator.Display = ValidatorDisplay.Dynamic;
Then i can display it to the page...
<CWC:TextBoxEmail RequiredField="True" ID="txtEmail" runat="server" />
But it never picks up the RequiredField property. Can someone point me in the right direction [:$]
Jan 10, 2008 10:56 PM|Mercury082|LINK
There is no property in that class called RequiredField....
Another thing worth mentioning.. is that you check the validateField value in the constructor. The ValidateField property probably won't be set already in the constructor, so it will always be false, and the validation stuff will never get added. Try adding
the validation further in the lifecycle... maybe something like this:
PreRender += delegate
// add validation stuff here
Jan 11, 2008 02:25 AM|Natural Cause|LINK
Woops i meant to type ValidateField.
Anyway i got it working by overing render and adding the stuff there. However!!!!!
I thought i might try adding a compare validator which does page.findcontrol and grabs the id to validate that control...
Doesn't seem to work tho :( Is that possible?
What happens is it says you cannot use the same value for the control to compare as the control to validate. Which is understandable. I thought of creating the textbox id as "InputField" + DateTime.Now.Millseconds.ToString();
Jan 14, 2008 12:07 AM|Nai-Dong Jin - MSFT|LINK
Just mentioned by Mercury, something like adding child controls would not be recommended to finish in constructor. They should be finished in CreateChildControls method.
Second, as you said that you want to add a compare validator controls. Well, no matter what kind of controls you want to add, you should expose some public properties which links to the properties of compare validator controls. So in this way, The child
control compare validator can community with other objects which is outside of the custom server control.