Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

validation control

Posted on 2006-07-21
7
Medium Priority
?
498 Views
Last Modified: 2008-01-09
i have a 2 combobox and a 1 textbox and a search button

1) country combobox
2) state combobox
3) textbox

when user click on search button without entering anything in the textbox  then i'm inforcing user to enter (1) country and (2) city name (first 3 characters) which works great  but i have a new requirement:

when the user select country = "United States" then i have to make sure user select

1)Country
2)State
3) city name (first 3 characters)

how do i do that?  
0
Comment
Question by:madina1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 15

Expert Comment

by:Hamidreza Vakilian
ID: 17157992
Hi!

add Item "NONE" to your state combobox for none USA countries ....
and add these lines to search button onclick event =>

if (countrycombo.Items.Item[countrycombo.SelectedIndex].ToString = 'United States') and (statecombo.Items.Item[statecombo.SelectedIndex].ToString <> 'NONE') and (sizeof(textbox1.text) >= 3 ) then
{goto next page}


HRV
0
 

Author Comment

by:madina1
ID: 17158047
i'm talking about validation control that come along with visual studio asp.net 2

may be i'm confused what you post
0
 
LVL 6

Accepted Solution

by:
NunoGodinho earned 200 total points
ID: 17158512
Hi,

   In your case the best way should be using a CustomValidator in order to make your own definitions of the validation strategy and so you sould implement something like this:

      - ASPX side

         <asp:CustomValidator id="CustomValidator1"
            ControlToValidate="cboCountry"
            Display="Static"
            ErrorMessage="Invalid information selected"
            ForeColor="green"
            Font-Name="verdana"
            Font-Size="10pt"
            OnServerValidate="ServerValidation"
            ClientValidationFunction="ClientValidate"
            runat="server"/>

            <script language="javascript">
                void ClientValidate(source, argument)            
                {
                     object cboCountry = document.GetElementById('cboCountry');
                     object cboState = document.GetElementById('cboState');
                     object txtCityName = document.GetElementById('txtCityName');

                     arguments.IsValid = (cboCountry.selectedIndex != 1 && cboCountry.value == 'United States' && cboState.selectedIndex != -1 && Trim(txtCityName).length > 0);
                }

            </script>

        - Code-behind

           void ServerValidation(object source, ServerValidateEventArgs args)
           {
                 args.IsValid = (cboCountry.SelectedIndex != -1 && cboCountry.SelectedValue.equals("United States") && cboState.SelectedIndex != -1 && txtCityName.Trim().length > 0);
           }


     This should do it.

       Nuno Godinho
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:madina1
ID: 17167656
Nuno Godinho:

a runtime error has occurred

line 50
error: expected '('

here is my aspx code:

<table style="width: 316px">
    <tr>
        <td style="width: 150px">
            <radcb:RadComboBox
                      id="ddlCountry"
                      Runat="server"
                      Height="140px"
                      Width="150px"
                      Skin="WindowsXP"                                          
                      ShowToggleImage="True"                                           
             
                  />
        </td>  
        <td style="width: 27px">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator_Country" runat="server" ControlToValidate="ddlCountry" ErrorMessage="Select Country" Display="Dynamic" Width="6px">*</asp:RequiredFieldValidator></td>
    </tr>
    <tr>
        <td style="width: 150px">
            <radcb:RadComboBox
                      id="ddlState"
                      Runat="server"
                      Height="140px"
                      Width="150px"
                      Skin="WindowsXP"
                      ShowToggleImage="True"                                          
      
                />
            <td style="width: 27px"><asp:RequiredFieldValidator ID="RequiredFieldValidator_State" runat="server" ErrorMessage="Select State" Width="6px" ControlToValidate="ddlState">*</asp:RequiredFieldValidator></td>
                <tr>
                <td style="height: 26px">
                        <asp:TextBox runat="server" ID="txt" Width="167px"></asp:TextBox>
                </td>
                <td style="width: 27px; height: 26px">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator_City" runat="server" ControlToValidate="txt" ErrorMessage="Enter City name" Width="6px" Display="Dynamic">*</asp:RequiredFieldValidator></td>
                    <td style="width: 291px; height: 26px;"><asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Help Me Choose</asp:LinkButton></td>
            </tr>
           
           
             </td>
                <td style="width: 27px">
                </td>
        </tr>
    </table>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
           

<script type="text/javascript">                              
    var _ddlState = <%= ddlState.ClientID %>;
    //
    function loadBuilding(item)
    {      
        _ddlState.SetText('<%=aspx_WaitLoading %>');
        if (item.Index > 0)
        {            
            _ddlState.RequestItems(item.Value, false);                                                                        
        }
        else
        {
            _ddlState.ClearSelection();
            _ddlState.SetText('<%= aspx_SelectBuilding %>');                
            _ddlState.RequestItems("", false);                
        }                              
    }
    //
    function ItemsLoaded(combo)
    {
        if (combo.Items.length > 0)
        {
            combo.SetText(combo.Items[0].Text);
        }
        combo.ShowDropDown();
    }
</script>
 
 
0
 

Author Comment

by:madina1
ID: 17167674
when i click on the button to select

i get the a error window:

microsoft jscript runtime error: object expected

ClientValidate(val, args);
0
 

Author Comment

by:madina1
ID: 17167919
Nuno Godinho

the best example is here

http://www.peterblum.com/vam/DemoAll.aspx

when you select "united states" or "canada" the STATE required field is popup

same exact thing i want to implement

thanks.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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