c# - Attach RequiredValidator on custom server control rendering a TextBox -


I do not know if this is actually possible, but I am doing my best.

If I have (complex) custom server control that provides a text box on the UI (next to other controls) when controlling the server on a page, does that server control a It would be possible to attach the RequiredField verifier, such as the validator validates the text property of the control that indicates the text property of the render text box?

Of course, I can include RequiredField Verifier directly in server control, but it is not possible for other reasons (we are automatically providing RequiredField validators on UI).

Thank you for your help.

I think a solution is to put your textbox control inside a panel, then you add dynamically requiredValidator control on pageLogo Handler

  & asp: panel id = "panel 1" runat = "server" & gt; & Lt; MyCustomTextBox ID = "Textbox 1" Runat = "Server" & gt; & Lt; / MyCustomTextBox & gt; & Lt; / ASP: Cell & gt; & Lt; ASP: Button ID = "Button 1" Runat = "Server" Text = "Button" />  

Then

  Protected Zero Page_load (Object Sender, EventEurge E) {var validator = new RequiredFieldValidator (); Validator.ControlToValidate = "TextBox1"; Validator.ErrorMessage = "This field is required!"; Panel1.Controls.Add (validator); }  

I have asked the custom textbox inside the panel to assure that when added, verification controle is correct


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -