How to iterate through various controls of all Views in a Multiview control and display a Summary message in ASP.Net?

I'm using a Multiview control having 6 views named as View1, View2,&.View6. I'm also using 6 LinkButtons named as  1 2 3 4 5 6 located at the bottom of the Multiview control. Each of the LinkButton when clicked causes a postback and sets the corresponding ActiveIndexView property of the Multiview control.

Each of the Views has controls like textboxes, dropdowns, checkboxes etc. which if the user is required to enter is indicated with a red * sign, but there are no validation controls used (because of the business rules).

View6 has a Submit Application button which when clicked should go through the controls of all the six views. If the user hasnt entered values for any of the required fields in any of the Views, it should give a summary kind of a message in the following format:

View1
First Name is required
View2
No. of years of Experience was not selected
View4
Person to contact was not entered.
View6
Hobbies not entered.

I'm using C# language as the code-behind.
pb102674Asked:
Who is Participating?
 
copyPasteGhostConnect With a Mentor Commented:
I posted :) feel free to close this question and we can resume on the other one.
0
 
copyPasteGhostCommented:
Why can't you use the validation controls....if you are going to build your own validation?
0
 
pb102674Author Commented:

This application is about a user having to fill an application form. Since it is a lengthy form, it has been divided into 6 views using Multiview. The user has seven days to fill this form after which his Login ID is disabled.

Each of the views has a SAVE button which submits the data entered into the database so that the user does not have to enter data all over again when he logs into the application again during the window of 7 days he has to complete the application.

The application is considered complete only after the user clicks the SUBMIT APPLICATION button which is on View6.

So to answer your question, I can use Validation controls but the validation summary has to be shown only after the user clicks the SUBMIT APPLICATION button on View6.
Or the other option would be to iterate through all controls of each view and display a custom summary message similar to the one I have mentioned in my question.

I would also like to point out that my scenario is very similar to this question:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24063320.html
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
copyPasteGhostCommented:
yes that is good you can base off that answer and if you get stuck post your code and I'm sure I'll be able to help you out.
0
 
copyPasteGhostCommented:
if you do validation after every page. (when the user clicks save) you will not have any problems.

I would do it that way. Validate every page. one at a time. and then when the user hits submit the form will already all be validated.

My opinion best approach by far.
0
 
pb102674Author Commented:
You suggestion is good, but as per the business rules, I can't implement validation on every page. The reason being there's a strong possibility that the user may not know some information when he's filling out a certain page and that's precisely the reason he has seven days to fill the form and the validation is done only after he clicks the SUBMIT APPLICATION button on View6 which is when the application is considered to be complete.

Could you please provide me a solution to iterate through all controls of each view and display a custom summary message similar to the one I have mentioned in my question? I have very little time left.

Thanks.
0
 
copyPasteGhostCommented:
you can create a :

string ValidateAll(){
//check if all items are valid.
StringBuilder sb = new StringBuilder();
if(txtFirstName.Text == ""){
sb.Append("Please enter your first name!<br />");
}
if(txtLastName.Text == ""){
sb.Append("Please enter your last name!<br />");
}

...
...
...
lblResults.Text = sb.ToString();
}

you can tigger that method when the user clicks on submit all.
The label for the lblResults can be placed where you want to see the validation summary.

I'm sure you can take it from here :)
Let me know if you need anything else.

I will only be able to respond in 15 hours or so...But this should get you well on your way.
0
 
pb102674Author Commented:
Yes I can definitely take it on from here. Thanks for your help. I'll close this question and award the points. Do you have time for another question that I will be posting in the next few minutes?
0
 
copyPasteGhostCommented:
:) maybe one more :)
0
 
pb102674Author Commented:
I appreciate your time and help. Here's the question link:

http://www.experts-exchange.com/index.jsp?qid=24386164
0
 
pb102674Author Commented:
Hi there,

I have a quick question in reference to the solution you provided. Let's say I'm using the code you've given for:
 string ValidateAll(){
//check if all items are valid.
StringBuilder sb = new StringBuilder();
if(txtFirstName.Text == ""){
sb.Append("Please enter your first name!<br />");
}
...

lblResults.Text = sb.ToString();
}

Assuming I'm iterating through all six views and let's say View 1 has 5 five required fields out of which the user hasn't entered values for 2 fields. View 2 has 5 five required fields and user enters all fields. View 3 has five required fields out of which user hasn't entered value of one field and so on...

What I'm doing right now is setting 6 boolean flags isPage1Error.......isPage6Error for the six views. When iterating through the View1, I'm setting the isPage1Error to true if the user hasn't entered values for the two fields. I'm doing this so that I can add the "View 1" line at the top of the error Message. Similarly, View 2 does not have any error messages so it won't be added. But in View 3, user hasn't entered a required field so "View 3" should be added to the error message. So, my final message should look like:

View 1
First Name Required.
Last Name Required.

View 3
No of years of experience Required.

What I'm trying to ask is how to get the lines View 1 and View 3 inserted into the error message because they are determined dynamically. Please help.
0
 
copyPasteGhostCommented:
Your problem is here:

>>What I'm doing right now is setting 6 boolean flags isPage1Error.......isPage6Error for the six views. When iterating through the View1, I'm setting the isPage1Error to true if the user hasn't entered values for the two fields.

Don't do that. You can do this:
List<string> sErrorList = new List<string>();
if (txtFristName.Text == ""){
sErrorList.Add("Missing First Name");
}
else if (txtLastName.Text == ""){
sErrorList.Add("Missing Last Name");
}

...

then to print out the results...
StringBuilder sb = new StringBuilder();
foreach(string sErrorItem in sErrorList ){
sb.Append(sErrorItem + "<br />");
}
 lblResults.Text +=sb.ToString();


If you want to use the same variable across all the views you can put the sErrorList in a ViewState variable and use it across your page.\

That should help solve that problem.
Ghost
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.