Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Does asp.net have something against afghanisatn?

  1. #1
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Does asp.net have something against afghanisatn?

    Ok, 2 files in question

    countries.xml
    Code:
    <Countries>
        <country>
            <value>
                Default
            </value>
            <name>
                -- Please Select --
            </name>
        </country>
        <country>
            <value>
                AF
            </value>
            <name>
                Afghanistan
            </name>
        </country>
    .
    .
    .
    regiester.aspx.vb
    Code:
    Protected Sub valCountry_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
            args.IsValid = (ddlCountry.SelectedValue.Length < 7)
        End Sub
    What should happen here is that user selects a country, if the lenght of the value for the country is less than 7 (i.e. not default) then a the drop down list is validated as being select and the form carry's on

    What happens is that if the user selects the default vakue then the validation works,

    if the user selects afghanistan then the validation does not work (i.e. say that country has not been selected)

    if the user select anything else it works fine (i.e. recognises that a country has been selected)

    I tried adding an extra country between default and afghanisatan, but afghanisatan would still not validate....

  2. #2
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This is actually getting worse, I now have 3 drop down list boxes all binded to XMl sources, all of which seem to be working differenlty, even tho in essence they are the same.

  3. #3
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    After looking everwhere for a solution and reading about using response methods and and all sorts to validate a drop down list box, it seem you can validate a drop-down-list using requiredfieldvalidator and the InitialValue property

  4. #4
    Join Date
    Jun 2005
    Posts
    1,081
    Thanks
    4
    Thanked 15 Times in 15 Posts

    Default

    I'm not sure how you are using the validators, but I would start by ensuring that Client-Side validation is turned off.

  5. #5
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Basically the idea s that there is a defalt value as the initial value (li.e value = default, name=Please Select) and the validator is supposed to check to make sure something other than the value 'default' has been selected (i.e. via dropdownlist.selecteditem.value <> "Default")

    But after reading some articles it seems that dropdowns don't work the same as normal controls when using validtion and return the default valueeverythime when using validation.

    So MSDN said use a required field validator and set the InitialValue proerpty (i.e. in my case InitialValue = "Default"), now this work for one of my dropdowns, but not the other two, even tho all 3 are exactly the same as each other, even bound the same way.

    The other problem is the other two dropdowns are not retaining their viewstate (and I even forced viewstate by setting ViewState=true)

    Confusing or what?

    Edit; Just disabled client validation, no help there

  6. #6
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh yea, and afganhistan still does not get validated as a vaild country!

  7. #7
    Join Date
    Feb 2004
    Posts
    4,901
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Quote Originally Posted by jaimalchohan
    Oh yea, and afganhistan still does not get validated as a vaild country!
    Because its first in the list?
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  8. #8
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Warren Ashcroft
    Because its first in the list?
    Its second.

    First is: value=Default text=-- Please Select --
    Second: value=AF text=Afghanistan
    Third: value=AL text=-- Albania

    Even with the below settings instead, afghanistan still doesn't get validated properly

    First is: value=Default text=-- Please Select --
    Second: value= text=
    Third: value=AF text=Afghanistan
    Fourth: value=AL text=-- Albania


    I am considering taking out country validation (don;t wanna do it) or doing it via vbscript (really don;t wanna do it)

  9. #9
    Join Date
    Jun 2005
    Posts
    1,081
    Thanks
    4
    Thanked 15 Times in 15 Posts

    Default

    I'm not sure, but I think you would need to look into doing custom validation on the drop down list.

    Since you turned off client-script the validation is running on the server. This is normally triggered by a Page.IsValid method and you would probably need to use Reflector or some other Disassembler to see what is going on in within that method.

    I personally haven't delved into using validation controls on a Drop Down List, instead I have handled it server side without the use of a Validation Control:

    Code:
    public void Submit_click(Object sender, EventArgs e)
    {
           if (Page.IsValid && ValidateForm())
           {
               // Form is valid, continue processing.
           }
           else
           {
               // Form is Invalid, present some info to the user
               // and re-display the form.
           }
    }
     
    public bool ValidateForm()
    {
           if ( ddlCountries.SelectedValue.Length >= 7)
           {
               // Country not selected
               //  Set an error msg to be displayed
               return false;      
           }
           
           return true;    
    }

  10. #10
    Join Date
    Mar 2005
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks sol, ill try it out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Localization in asp.net 2.0
    By psykik in forum ASP.NET
    Replies: 4
    Last Post: 25th April 2006, 08:05 AM
  2. ASP.NET book
    By creativeworks in forum ASP.NET
    Replies: 4
    Last Post: 7th February 2006, 02:28 PM
  3. asp.net db connection
    By creativeworks in forum ASP.NET
    Replies: 34
    Last Post: 8th November 2005, 03:53 PM
  4. ASP.net 2.0
    By JohnnyW in forum Sales and Service Feature Enquiries
    Replies: 17
    Last Post: 8th November 2005, 01:01 PM
  5. ASP.NET tutorials
    By Octavius in forum ASP.NET
    Replies: 3
    Last Post: 24th September 2005, 03:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •