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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable invisible controls

    Hi,
    I'm building an application in asp.net where only a portion of the controls on a page is visible, depending of the access of the user logged in at the moment.
    On some pages I have radiobuttons to enable a part of a page, and disable another. The enabling/disabling is done with javascript. The problem is that the javascript is not able to disable/enable controls that are invisible at the moment. Why is that so?

    I guess I could make several disable/enable scripts depending on the access of the user, but I would rather not.

    Thankful for any tip I can get.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Can you give us something to work with? A link to the scripts in action, or at least a codee sample?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Of course.

    My .aspx-file contains among other things two radiobuttons, and they call a javascript function enableChangeInfo(param) as their onclick-method. One of them send true as param and the other one false.

    My script looks as follows:

    function enableChangeInfo(param)
    {
    document.getElementById('lblIntervalStart').disabled = param;
    document.getElementById('txtIntervalStart').disabled = param;
    document.getElementById('imgbtnIntervalStart').disabled = param;
    document.getElementById('radioIntervalStart').disabled = param;
    document.getElementById('lblIntervalEnd').disabled = param;
    document.getElementById('txtIntervalEnd').disabled = param;
    document.getElementById('imgbtnIntervalEnd').disabled = param;
    document.getElementById('radioIntervalEnd').disabled = param;
    document.getElementById('chkOvertime').disabled = param;
    document.getElementById('cboOvertime').disabled = param;
    document.getElementById('lblOvertime').disabled = param;
    document.getElementById('chkWeekend').disabled = param;
    document.getElementById('chkFix').disabled = param;
    document.getElementById('lblComment').disabled = param;
    document.getElementById('txtComment').disabled = param;
    }

    The five controls chkOvertime, cboOvertime, lblOvertime, chkWeekend and chkFix are either visible or invisible depending on the user who is watching the page. Their visibility is set in the page_load method in the codebehind file.

    When I run the application with all the controls visible (administrator mode), the script works fine, but when one or more of the controls mentioned above is made invisible, the script debugger says that:
    "document.getElementById()' is null or not an object".

    Can I work around this in some way?

    Thanks in advance

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know if you've spotted this, but if a user (who is not an administrator) was to simply copy your source code and make the controls visible, they could make the changes they want and submit the form to your server. Therefore, even though they are not an Admin, they could still make use of all of the controls.
    In fact, to users without JavaScript enabled, they would see all of the admin controls anyway.

    It would be much safer if you were to "hide" the controls using ASP.net by either writing or not writing those input fields to the page. If you were to do that then your current problem should just disappear.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150


  •  

    Posting Permissions

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