Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    ASP:Dropdownlist naming?

    I've go a problem with a piece of ASP code that I'm hoping someone will be able to help with?

    I'm using an ASP:dropdownlist box to pull some info from a DB, however the page I'm using it on writes the form information back in C#, which means it won't see the drop down unless it has a name, not an ID.

    I know that its not as simple as just adding name="appID" in the drop down, because I've tried that already, and it doesn't work.

    The c# command for the other fields in the form is:
    (Request.Form["Appointment"] != null ? Convert.ToString(Request.Form["Appointment"]).Replace("\"", "\"\"") : "") +

    for writing other standard input fields back to the DB, but I don't know how to do it for ASP drop downs, can anyone help?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    First of all, you are talking about ASP.NET, not ASP. So technically you are in the wrong forum.

    However...

    ASP.NET *always* assigns a name= to form fields, including dropdownlist.

    So you could simply bring the page up in a browser, click on the VIEW menu, click on the SOURCE menu item, and then look in the HTML that ASP.NET is generating to find the name it uses.

    HOWEVER... If you are using Request.Form to get values from ASP.NET controls, you are really not using ASP.NET the way it was designed to be used.

    Look here:
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    That shows how you should be capturing "onchange" for asp:dropdownlist.

    Generally speaking, if you find yourself using Request.Form a lot, you haven't really bought into the ASP.NET way of handling forms.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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