Advertisement

09.06.2008 at 10:31PM PDT, ID: 23709707
[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!

8.0

validation group

Asked by -Dman100- in Programming for ASP.NET, Visual Studio

I am setting up validation on a webform and I have a 4 dropdownlists that a user can select a time...i.e.
hours, minutes, am/pm, and time zone.

I've made each dropdownlist required using 4 separate required field validators.  I'm using the same error message for each of the four required field validators.

When I submit the form and the time has not been selected, all four error messages display.  I only want the the error message to display once until all four dropdowns have been properly selected and then of course the validation will be correct and the error message wouldn't display.

Can I use a validation group to only display the error message once?  If not, how can I accomplish this?

See below for the page code:Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
aspx page code:
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdobeSessions.aspx.cs" Inherits="AdobeSessions" Title="Adobe Online Session Request" %>
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
    .modalBackground {
        background-color:Gray;
        filter:alpha(opacity=70);
        opacity:0.7;
     }
     .modalPopup {
        background-color:#ffffdd;
        border-width:3px;
        border-style:solid;
        border-color:Gray;
        padding:3px;
        width:500px;
     }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Label ID="lblFormTitle" runat="server" Font-Bold="True" Font-Size="X-Large"
            Text="<p>Adobe <sup>&reg;</sup> Acrobat <sup>&reg;</sup> Connect<sup>TM</sup> Pro Session REQUEST FORM</p>"></asp:Label>
        <table width="675" cellpadding="5" cellspacing="0" border="0">
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:RequiredFieldValidator ID="valrRequestor" runat="server" ControlToValidate="txtRequestor"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" SetFocusOnError="True">* Name of person requesting session:</asp:RequiredFieldValidator>
        <asp:Label ID="lblRequestor" runat="server" Text="Name of person requesting session:"></asp:Label></td>
                <td>
        <asp:TextBox ID="txtRequestor" runat="server" Width="265px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" style="width: 300px" valign="top">
                    <asp:RequiredFieldValidator ID="valrRegion" runat="server" ControlToValidate="ddlRegion"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Region:" InitialValue="-1" SetFocusOnError="True">* Region:</asp:RequiredFieldValidator>
                    <asp:Label ID="lblRegion" runat="server" Text="Region:"></asp:Label></td>
                <td>
                    <asp:DropDownList ID="ddlRegion" runat="server">
                        <asp:ListItem Selected="True" Value="-1">Select</asp:ListItem>
                        <asp:ListItem Value="Northeast">Northeast</asp:ListItem>
                        <asp:ListItem>Mid-Atlantic</asp:ListItem>
                        <asp:ListItem>South</asp:ListItem>
                        <asp:ListItem>West</asp:ListItem>
                        <asp:ListItem>Mid-West</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:RequiredFieldValidator ID="valrLeader" runat="server" ControlToValidate="txtLeader"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Name of person to lead sessioin:"
                        SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:Label ID="lblLeader" runat="server" Text="Name of person to lead session:"></asp:Label></td>
                <td>
        <asp:TextBox ID="txtLeader" runat="server" Width="265px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:RequiredFieldValidator ID="valrTitle" runat="server" ControlToValidate="txtTitle"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Title of Session:"
                        SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:Label ID="lblTitle" runat="server" Text="Title of Session:"></asp:Label></td>
                <td>
        <asp:TextBox ID="txtTitle" runat="server" Width="265px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:RequiredFieldValidator ID="valrDescription" runat="server" ControlToValidate="txtDescription"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Description:"
                        SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:Label ID="lblDescription" runat="server" Text="Description:"></asp:Label></td>
                <td>
        <asp:TextBox ID="txtDescription" runat="server" Width="265px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:RegularExpressionValidator ID="valeDate" runat="server" ControlToValidate="txtDate"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Date needed:"
                        SetFocusOnError="True" ValidationExpression="^\d{1,2}\/\d{1,2}\/\d{4}$"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="valrDate" runat="server" ControlToValidate="txtDate"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Date needed:"
                        SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:Label ID="lblDate" runat="server" Text="Date needed:"></asp:Label></td>
                <td>
        <asp:TextBox ID="txtDate" runat="server" Width="65px"></asp:TextBox>
        <asp:Image ID="imgCalendar" runat="server" ImageUrl="~/Images/cal.gif" />
        <cc1:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="imgCalendar"
            TargetControlID="txtDate">
        </cc1:CalendarExtender>
                </td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:RequiredFieldValidator ID="valrZone" runat="server" ControlToValidate="ddlZone"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Time needed:"
                        InitialValue="-1" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="valrAMPM" runat="server" ControlToValidate="ddlAMPM"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="Time needed:"
                        InitialValue="-1" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="valrMinutes" runat="server" ControlToValidate="ddlMinutes"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Time needed:"
                        InitialValue="-1" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="valrHours" runat="server" ControlToValidate="ddlHours"
                        Display="Dynamic" EnableClientScript="False" Enabled="False" ErrorMessage="* Time needed:"
                        InitialValue="-1" SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:Label ID="lblTime" runat="server" Text="Time needed:"></asp:Label></td>
                <td>
                    <asp:DropDownList ID="ddlHours" runat="server">
                    </asp:DropDownList>
                    <asp:DropDownList ID="ddlMinutes" runat="server">
                        <asp:ListItem Value="-1">Select</asp:ListItem>
                        <asp:ListItem Value="00">:00</asp:ListItem>
                        <asp:ListItem Value="15">:15</asp:ListItem>
                        <asp:ListItem Value="30">:30</asp:ListItem>
                        <asp:ListItem Value="45">:45</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="ddlAMPM" runat="server">
                        <asp:ListItem Value="-1">Select</asp:ListItem>
                        <asp:ListItem>AM</asp:ListItem>
                        <asp:ListItem>PM</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="ddlZone" runat="server">
                        <asp:ListItem Value="-1">Select</asp:ListItem>
                        <asp:ListItem>EST</asp:ListItem>
                        <asp:ListItem>CST</asp:ListItem>
                        <asp:ListItem>MST</asp:ListItem>
                        <asp:ListItem>PST</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
        <asp:Label ID="lblDuration" runat="server" Text="Duration of session:"></asp:Label></td>
                <td>
                    <asp:TextBox ID="txtDuration" runat="server" Width="265px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                    <asp:Label ID="lblSessionType" runat="server" Text="Type of Session:"></asp:Label></td>
                <td>
                    <asp:RadioButtonList ID="rblExternalInternal" runat="server" RepeatColumns="3"
                        RepeatDirection="Horizontal" RepeatLayout="Flow" OnSelectedIndexChanged="rblExternalInternal_SelectedIndexChanged" AutoPostBack="True">
                        <asp:ListItem>Internal</asp:ListItem>
                        <asp:ListItem>External Non-Billable</asp:ListItem>
                        <asp:ListItem>External Billable</asp:ListItem>
                    </asp:RadioButtonList></td>
            </tr>
            <asp:Panel ID="pnlParticipants" runat="server" Visible="False">
            <tr>
                <td align="right" valign="top" style="width:300px">
                    <asp:Label ID="lblParticipants" runat="server" Text="Names and email addresses for ALL participants (internal and external)"></asp:Label>
                </td>
                   <td><asp:GridView ID="GridView1" runat="server" CellPadding="5" Width="350px">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:GridView></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width:300px"><asp:Label ID="lblSiteName" runat="server" Text="Site/District Name:"></asp:Label></td>
                <td><asp:TextBox ID="txtSiteName" runat="server" Width="260px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width:300px"><asp:Label ID="lblLabNumber" runat="server" Text="Lab Number:"></asp:Label></td>
                <td><asp:TextBox ID="txtLabNumber" runat="server" Width="260px"></asp:TextBox></td>
            </tr>
            </asp:Panel>
            <tr>
                <td align="right" valign="top" style="width: 300px">
        <asp:Label ID="lblConferenceCall" runat="server" Text="Do you need a conference call number for the audio portion of the session?"></asp:Label></td>
                <td valign="bottom">
                    <asp:RadioButtonList ID="rblConferenceCall" runat="server" RepeatColumns="2"
                        RepeatDirection="Horizontal" RepeatLayout="Flow" AutoPostBack="true">
                        <asp:ListItem>Yes</asp:ListItem>
                        <asp:ListItem>No</asp:ListItem>
                    </asp:RadioButtonList></td>
            </tr>
            <tr>
                <td align="right" valign="top" style="width: 300px">
                </td>
                <td>
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
                    <asp:Button ID="btnReset" runat="server" OnClick="btnReset_Click" Text="Reset" /></td>
            </tr>
        </table>
        <asp:Panel ID="pnlAddParticipants" runat="server" CssClass="modalPopup" style="display:none;">
        <table width="500" cellpadding="5" cellspacing="0" border="0">
            <tr>
                <td align="right" valign="top">
                    <asp:Label ID="lblName" runat="server" Text="Participant Name:"></asp:Label></td>
                <td>
                    <asp:TextBox ID="txtName" runat="server" Width="260px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top">
                    <asp:Label ID="lblEmail" runat="server" Text="Email Address:"></asp:Label></td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server" Width="260px"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="right" valign="top">
                </td>
                <td>
                    <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
                    <asp:Button ID="btnClose" runat="server" Text="Close Window" />
                    </td>
            </tr>
        </table>
        </asp:Panel>
        <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="HiddenField1" PopupControlID="pnlAddParticipants" BackgroundCssClass="modalBackground" DropShadow="true"  >
        </cc1:ModalPopupExtender>
        <asp:HiddenField ID="HiddenField1" runat="server" />
    </div>
    </form>
</body>
</html>
 
 
code-behind:
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class AdobeSessions : System.Web.UI.Page
{
    DataTable myDt = null;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadHours();
 
            myDt = new DataTable();
            myDt = CreateDataTable();
            Session["myDatatable"] = myDt;
 
            this.GridView1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
            this.GridView1.DataBind();
        }
    }
 
    protected void LoadHours()
    {
        ddlHours.Items.Add(new ListItem("Select", "-1"));
        for (int i = 1; i <= 12; i++)
        {
            ddlHours.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }
 
    protected void btnReset_Click(object sender, EventArgs e)
    {
        cleanFields(this);
    }
 
    protected void cleanFields(Control container)
    {
        foreach (Control c in container.Controls)
        {
            if (c is TextBox)
            {
                ((TextBox)c).Text = string.Empty;
            }
            if (c is DropDownList)
            {
                ((DropDownList)c).SelectedIndex = 0;
            }
            if (c is RadioButtonList)
            {
                ((RadioButtonList)c).ClearSelection();
            }
            this.cleanFields(c);
        }
        pnlParticipants.Visible = false;
        DataTable dt = new DataTable();
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
 
    protected void rblExternalInternal_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rblExternalInternal.SelectedItem.Value.ToString().ToLower() == "external billable")
        {
            this.ModalPopupExtender1.Show();
            pnlParticipants.Visible = true;
        }
        else
        {
            pnlParticipants.Visible = false;
        }
    }
 
    private DataTable CreateDataTable()
    {
        DataTable myDataTable = new DataTable();
 
        DataColumn myDataColumn;
 
        myDataColumn = new DataColumn();
        myDataColumn.DataType = Type.GetType("System.String");
        myDataColumn.ColumnName = "Name";
        myDataTable.Columns.Add(myDataColumn);
 
        myDataColumn = new DataColumn();
        myDataColumn.DataType = Type.GetType("System.String");
        myDataColumn.ColumnName = "Email";
        myDataTable.Columns.Add(myDataColumn);
 
        return myDataTable;
    }
 
    private void AddDataToTable(string name, string email, DataTable myTable)
    {
        DataRow row;
 
        row = myTable.NewRow();
 
        row["Name"] = name;
        row["Email"] = email;
 
        myTable.Rows.Add(row);
    } 
 
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        this.ModalPopupExtender1.Show();
        AddDataToTable(this.txtName.Text.Trim(), this.txtEmail.Text.Trim(), (DataTable)Session["myDatatable"]);
 
        this.GridView1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
        this.GridView1.DataBind();
 
        this.txtName.Text = "";
        this.txtEmail.Text = "";
    }
 
    protected void EnableValidators(bool toggle)
    {
        valrRequestor.Enabled = toggle;
        valrRegion.Enabled = toggle;
        valrLeader.Enabled = toggle;
        valrTitle.Enabled = toggle;
        valrDescription.Enabled = toggle;
        valrDate.Enabled = toggle;
        valeDate.Enabled = toggle;
        valrHours.Enabled = toggle;
        valrMinutes.Enabled = toggle;
        valrAMPM.Enabled = toggle;
        valrZone.Enabled = toggle;
    }
 
    protected void ValidateControls()
    {
        Label[] controls = { lblRequestor, lblRegion, lblLeader, lblTitle, lblDescription, lblDate, lblTime };
        IValidator[][] validators = { new IValidator[] { valrRequestor }, 
            new IValidator[] { valrRegion }, new IValidator[] { valrLeader },
            new IValidator[] { valrTitle }, new IValidator[] { valrDescription },
            new IValidator[] { valrDate, valeDate }, new IValidator[] { valrHours, valrMinutes, valrAMPM, valrZone }};
 
        for (int i = 0; i < controls.Length; i++)
        {
            bool valid = true;
            foreach (IValidator validator in validators[i])
            {
                valid &= validator.IsValid;
            }
            controls[i].Visible = valid;
        }
    }
 
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        EnableValidators(true);
 
        Page.Validate();
 
        if (Page.IsValid)
        {
            //cleanFields(this);
        }
        else
        {
            ValidateControls();
        }
 
    }
}
[+][-]09.06.2008 at 11:14PM PDT, ID: 22410337

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

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

 
[+][-]09.06.2008 at 11:35PM PDT, ID: 22410383

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.

 
[+][-]09.06.2008 at 11:38PM PDT, ID: 22410387

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: Programming for ASP.NET, Visual Studio
Sign Up Now!
Solution Provided By: BondinASP
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628