Processing disabled form fields

Last post 03-20-2007 10:09 PM by Armaghan. 8 replies.

Sort Posts:

  • Processing disabled form fields

    03-19-2007, 11:23 AM
    • Loading...
    • Armaghan
    • Joined on 05-31-2005, 4:01 PM
    • Houston
    • Posts 31

    Hi,

    On my page I have several DropDownLists that I'm enabling and disabling them through javascript, depending on the user's actions.

    Now the problem is, how can I check which DDLs were disabled by javascript when the form is posted. I tried DDLName.Enabled property but it always returns True (as the dropdownlist were enabled initially).

    In classic ASP disabled form fields were not posted to the server so you could check if certain fields are not in the Request.Form Collection, but I couldn't figure this out in ASP.net 2.0.. Please help!

    Computers are not intelligent. They only think they are.
  • Re: Processing disabled form fields

    03-19-2007, 6:19 PM
    • Loading...
    • mosessaur
    • Joined on 07-11-2002, 6:40 PM
    • Cairo
    • Posts 352

    I think you'll need to go around this issue, according to my knowledge, you cannot get the value of disabled property of DropDownList in server side -during post back- if you set it on client side.

    One of the ideas to work arround this is to add a server side hidden field that will be flagged when your DropDownList list is disabled on client side, you will set the value property of the hidden field, and you can read it during PostBack.

    Muhammad M. Mosa Soliman
    Software Engineer
    Moses's Blog
  • Re: Processing disabled form fields

    03-19-2007, 6:25 PM
    • Loading...
    • JoshStodola
    • Joined on 01-16-2007, 9:17 AM
    • Heartland of America
    • Posts 3,025

    Perhaps instead of enabling/disabling them, a better approach would be to show/hide.  Personally, I think its more visually appealing.  Example:

        // Hide
        document.getElementById('DropDownList1').style.display = 'none';
    
        // Show
        document.getElementById('DropDownList1').style.display = 'inline';
     

    Hope this helps!  Don't forget to mark the most helpful post(s) as Answer for the sake of future readers.  Thanks!

    Josh Stodola ← Come check out my blog!
  • Re: Processing disabled form fields

    03-20-2007, 11:05 AM
    • Loading...
    • Armaghan
    • Joined on 05-31-2005, 4:01 PM
    • Houston
    • Posts 31

    Thank you for your replies. See the problem is, I'm hiding as well as disabling the DropDownLists on the client side. But once the form is submitted how can I tell if certain DDLs were disabled? ddl.enabled does not work as it always returns true even though my DDL were disabled on the clientside.

    Computers are not intelligent. They only think they are.
  • Re: Processing disabled form fields

    03-20-2007, 11:10 AM
    • Loading...
    • JoshStodola
    • Joined on 01-16-2007, 9:17 AM
    • Heartland of America
    • Posts 3,025

    From your code-behind, I don't think you can detect any changes made with javascript.  But, you might try this, though I doubt it will work:  

        If IsPostBack Then
           If DropDownList1.Style.Item("display") Is Nothing
               'DDL is visible
           ElseIf DropDownList1.Style.Item("display") <> "none" Then
               'DDL is visible
           Else
               'DDL is invisible
           End If
        End If
     

    Hope this helps!

    Josh Stodola ← Come check out my blog!
  • Re: Processing disabled form fields

    03-20-2007, 11:25 AM
    • Loading...
    • Armaghan
    • Joined on 05-31-2005, 4:01 PM
    • Houston
    • Posts 31

    No Sir! it did not work. See in when using classic ASP disabled fields are not submitted to the server thus they never appear in the Requst.form collection. So why does it do it in ASP.net?

    If we cannot detect any client side change in our code behind, is there any workaround except creating hidden fields?

    Computers are not intelligent. They only think they are.
  • Re: Processing disabled form fields

    03-20-2007, 11:25 AM
    • Loading...
    • Armaghan
    • Joined on 05-31-2005, 4:01 PM
    • Houston
    • Posts 31

    No Sir! it did not work. See when using classic ASP disabled fields are not submitted to the server thus they never appear in the Requst.form collection. So why does it do it in ASP.net?

    If we cannot detect any client side change in our code behind, is there any workaround except creating hidden fields?

    Computers are not intelligent. They only think they are.
  • Re: Processing disabled form fields

    03-20-2007, 2:26 PM
    • Loading...
    • upgView
    • Joined on 09-21-2006, 3:13 AM
    • Posts 147

    Hi,

    You disabled the dropdownlist, it is not sent to server, so you must provide other information instead, and hidden field is most suitable.

    I think everytime you disable a dropdownlist, you can add hidden field respectively, and vice versa. 

    At server side you can use the hidden field value to detect which dropdownlists were disabled.

    Hope this helps. 

    Trirange Portal Server Online Demo
    http://www.trirange.com/demo/
  • Re: Processing disabled form fields

    03-20-2007, 10:09 PM
    Answer
    • Loading...
    • Armaghan
    • Joined on 05-31-2005, 4:01 PM
    • Houston
    • Posts 31

    Actually I finally figured out a workaround. Instead of creating all those hidden fields you can simply check the Request.Form collecton.

    if particular field is not included in the Request.form collection then it has been disabled on the client side because disabled fields are not sent to the server for processing. Since I'm using a Master page you can use the Request.Form collection like this.

    if Request.form(lstFrom2.clientID.replace("_", "$")) = Nothing then
        'Field is disabled
    else
        Dim val as String = lstFrom2.SelectedValue
    end if

    But thanks to everybody who pitched in to help.

    Computers are not intelligent. They only think they are.
Page 1 of 1 (9 items)
Microsoft Communities
Page view counter