[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Validating controls in a custom user control

Asked by santaspores1 in VB Controls, Microsoft Visual Basic.Net

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:Label>
&      
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_EnterMonkeyId_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?
[+][-]08/18/09 09:08 AM, ID: 25124702Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: VB Controls, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: shahprabal
Participating Experts: 1
Solution Grade: A
 
[+][-]08/18/09 11:54 AM, ID: 25126308Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/18/09 12:26 PM, ID: 25126623Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625