Solved

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

Posted on 2009-05-06
12
570 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:pb102674
  • 7
  • 5
12 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24316832
Why can't you use the validation controls....if you are going to build your own validation?
0
 

Author Comment

by:pb102674
ID: 24317740

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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24317774
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24317798
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
 

Author Comment

by:pb102674
ID: 24317935
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24318011
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
 

Author Comment

by:pb102674
ID: 24318114
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24318141
:) maybe one more :)
0
 

Author Comment

by:pb102674
ID: 24318197
I appreciate your time and help. Here's the question link:

http://www.experts-exchange.com/index.jsp?qid=24386164
0
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 500 total points
ID: 24318389
I posted :) feel free to close this question and we can resume on the other one.
0
 

Author Comment

by:pb102674
ID: 24386191
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24387736
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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question