I would like to know how to go about validating controls in a custom user control.
I have an aspx page that has two sections - one section for gathering input and one section for displaying output. The sections are DIVs that I show or hide as required.
Currently, my aspx file has a number of user input controls on it.
The .vb file has a sub that handles the submit_form.Click.
That sub starts by validating all of the user input.
If any control has an invalid value, an error label under that control gets set to visible and the page stops processing data and waits for the next submit.click
If all of the controls have valid data then the input section is hidden and the processing takes place and the output section is shown.
Now& I want to change one of the user-input controls to a custom user control. So I now have a .ascx and a .ascx.vb file.
I moved my user-input control (a textbox) to the .ascx file.
I want my .ascx.vb file to have a sub that will check the value of the textbox and do some custom error handling (more than the sort of stuff that valuator controls do.
I have two questions:
1. What event should I handle in the .ascx.vb so that when a user clicks the submit button on my .aspx page the new custom user control is validated along with all of my other controls?
2. If I use the custom user control and custom validation, how can I tell my aspx page to show or hide the input/output sections as appropriate?
Here is some code:
ASPX file
&
Enter a monkey id
<asp:TextBox ID=monkey_id runat="server" MaxLength="9" Columns="9"></asp:TextBox>
<asp:Label ID="monkey_id_error" Text=" " runat="server" Visible="false"></asp:Labe
l>
&
several more input controls
&
<asp:Button id="submit_form" text="Submit Form" runat="server" />
&
ASPX.VB
Protected Sub submit_form_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit_form.Click
InputSection.Visible=True
monkey_id_error.Visible = False
If (monkey_id Value is invalid&) then
monkey_id_error.Visible = True
monkey_id_error.ForeColor = Drawing.Color.Red
monkey_id_error.Text = "<br />* You enter a valid monkey id."
page_errors = True
End if
&.
several more controls are tested
&
If (page_errors = False) then
process code
hide the input section
display the output section
end if
But now I want to move the monkey id text box to a user control so I have a
UserControl_EnterMonkeyId.
asc file
<asp:TextBox
ID=UserControl_EnterMonkey
Id_id
runat="server"
MaxLength="9"
Columns="9" >
</asp:TextBox>
And I have a UserControl_EnterMonkeyId.
asc file
What do I handle here to check for valid UserControl_EnterMonkeyId_
id values, and how do I basically accomplish setting page_errors = False in the aspx file?