Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Validation Control Question 1

Status
Not open for further replies.

IT4EVR

Programmer
Feb 15, 2006
462
US
Is there a way to collectively validate data in a GridView at once, and then fire a data validation control to display a required field label?

From what I understand, the validation control has to be implemented in a template control and then only validates the actual row being edited.

My thoughts were to create a method that iterates through all the GridView rows when clicking a button. That works but I am still not able to access the validation control for that row.

The reason I ask is if you are only validating the edited row, someone could answer some of the questions, but not all, and then redirect to another page.

Another idea I had would be to use JavaScript DOM.

Any thoughts?
 
do you want them to answer all questions or are they allowed to answer only some? When do you plan on redirecting?
 
IT4EVR,

Why dont you research the ValidationSummary control.

When using it set your Text property of your valdator control to something like * and the ErrorMessage to what you want displayed in the ValidationSummary object.

Hope this helps!

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
I want the user to redirect only when they have answered all questions.

The possible answers are None, Comply, Non Comply. I have the GridView set up with a SurveyID (PK), SurveyQuestion and SurveyAnswer fields. SurveyAnswer is a templated RadioButtonList control. I only show the RadioButtonList when they are editing.

Before a user begins a survey, I insert a default value of None in the SurveyResults table so that all questions are viewable.

The problem with this scenario is that a user could answer some of the questions and then redirect off the page, without answering all questions. It's my understanding that the validation controls only validate the edited row, not all at once.

If I could use the validation control, I could run this on Page_Unload?

Code:
private void Page_Unload(object sender, EventArgs e)
{
     if(Page.IsValid)
     {
         Response.Redirect("SurveySummary.aspx");
     }
}
 
YOu will have to validate the control so that "None" is not a valid answer and the page.IsValid will fail.
 
That makes sense and that was what I intended, but how do you validate if you aren't editing the row?
 
If you are looping throgh the rows and any one of the drop downs = "None" then set the page.isvalid to false.
 
Actually I tried that one and I received an error that Page.IsValid is a read-only property.
 
You can use a custom validator, and in the server_validate method of the contro, loop through and if the ddl is "none" set args.isvalid = false

Then check the page.isvalid property and redirect if TRUE
 
I'll give that a whirl and I'll let you know how it works out tonight.

Thanks for the reply.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top