Advertisement

05.13.2008 at 12:51PM PDT, ID: 23399189
[x]
Attachment Details

Why my validationGroup is not working?

Asked by eddyperu in C# Programming Language, JavaScript, .NET

Tags: javascript,C#, asp.net 2.0

Hi experts!!!
I have three pages: Page1.aspx, Page2.aspx, Page3.aspx. Each page have a Web User control named "general" which contain 4 controls. Also each pages have their own controls(4 or 5  textboxes).
I am trying to use the validationgroup to pop up an error message.
This validationgroup is been triggered by a button called "Next" which allow the client to go to the next page.
If the client is in the Page1.aspx and it doesn't  fill out all the fields in the page1  then the client can't go to Page2.aspx.(A pop up message will appear).
Sound easy......???:) Well The ValidationGroup is working in my 4 or 5 textboxes that belong to each page. But  the ValidationGroup  doesn't want to work for any of the controls iniside the Web User Control.
Right now, the client can leave a field without fill it out from the Web User Control(general) and click the button "Next"  and it will send the client to the next page. The validationgroup  inside my web user control is not working.

I am attaching my code so you can see it more clearly.
Another thing that I have noticed after see the "VIew Source" is that the validationgroup inside the web user control look like this:
generalSection_MaskedEditValidator2.validationGroup = "<%=Valuerequired%>";

It looks like is reading the value of the validation Group as a string Eventhoug I am passing a value for it in the code behind, If you see my code It will make more sence.

Thanks!

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:
Javascript in the page.aspx:
<script>
      function clientValidation() 
       { 
         var returnvalue = true;
         var validated = Page_ClientValidate('LTC');
         if(!validated)
         {
           $find('MyMPE2').show();
         }       
          return returnvalue;
      
    }
    </script>
 
Button that trigger the script:
<asp:ImageButton ImageUrl="images/NextPage.png" ID="imgbtnNext" runat="server" OnClientClick="return clientValidation()"/>
 
Modal Pop up Extender, my asp panel and a dummy button:
<div style="clear:both; margin:10px 0px">
   <asp:Button ID="dummybutton"runat="server"style="display:none" />    
</div>  
<div>
  <asp:Panel runat="server" ID="PanelProductEnroller1"
              style="display:none" CssClass="modalPopup">
       <table>
         <tr>
           <td valign="top">
             <table>
                <tr>
                  <td>                               
                  <asp:Button ID="btnIagree2" runat="server"                               Text="Continue"UseSubmitBehavior="False"  /><asp:ImageButton ID="CancelButton2" runat="server" ImageUrl="../images/OK.png"/>
                          </td>
                        </tr>
                      </table>
                    </td>
                 </tr>   
              </table>
          </asp:Panel>
 
              <asp:ModalPopupExtender ID="MyMPE2" runat="server" 
                         TargetControlID="dummybutton" 
                         PopupControlID="PanelProductEnroller1"  
                         BackgroundCssClass="modalBackground"          
                         OkControlID="btnIagree2"                   
                         CancelControlID="CancelButton2"
                         BehaviorID="MyMPE2"
                       PopupDragHandleControlID="PanelProductEnroller1">
              </asp:ModalPopupExtender>
          </div>     
 
 
Examples of one of my controls in the page with the validation group:  
<asp:DropDownList ID="ddlWhoPays" runat="server" Width="155px">
<asp:ListItem Value="-1">Select One...</asp:ListItem>
<asp:ListItem Value="EE">Employee </asp:ListItem>                 
 <asp:ListItem Value="EF">Employer </asp:ListItem>                  
 </asp:DropDownList> <span class="error">*</span> 
<asp:CompareValidator ID="compareValidatorPlaneWhoPays" runat="server"  ErrorMessage="Required" Display="Dynamic" CssClass="error" ControlToValidate="ddlLTCPlaneWhoPays" ValidationGroup="group1" ValueToCompare="-1" Operator="NotEqual">Required</asp:CompareValidator>
 
Example of one of the controls in my Web user control:
 <asp:textbox id=txtPN runat="server"></asp:textbox>
 <span class=error>*</span> 
 <asp:requiredfieldvalidator id=requiredFieldValidatorPolicyNumber  
   ValidationGroup="<%=Valuerequired%>" ForeColor="" runat="server" 
   ErrorMessage="Required" Display="Dynamic" CssClass="error"    ControlToValidate="txtPN">Required</asp:requiredfieldvalidator>
 
This is the code behind from my Web User Control:
protected string Valuerequired;
string pageURL = Page.Request.Path.Substring(Request.Path.LastIndexOf("/") + 1).ToString().ToLower(); 
         switch (pageURL)
         {
             case "page1.aspx":
                 tableImageURL = "../images/LightBlue_general_information.png";
                 Valuerequired = "group1";
                 break;
             case "page2.aspx":
                 tableImageURL = "../images/Orange_general_information.png";
                 Valuerequired = "group2";
                 break;
             case "page3.aspx":
                 tableImageURL = "../images/Yellow_general_information.png";
                 Valuerequired = "group3";
                 break;
         }
[+][-]05.13.2008 at 09:25PM PDT, ID: 21561252

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 03:50AM PDT, ID: 21562722

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.14.2008 at 05:43AM PDT, ID: 21563453

View this solution now by starting your 7-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: C# Programming Language, JavaScript, .NET
Tags: javascript,C#, asp.net 2.0
Sign Up Now!
Solution Provided By: eddyperu
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628