Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
560
Webcombo readonly?
posted

Can a webcombo be made to be readonly so that a user cannot change the value it contains?

 

Thanks,

Dave

Parents
No Data
Reply
  • 105
    posted

    Hi Dave,

    I just ran into a similar yet simpler problem and could not find any suggestion by either Infragistics support or other developers.  I just wanted to make some webcombo controls on my screen readonly (or disabled) based on the selected value of a controlling webcombo - so the selected value of a particular webcombo causes some predefined fields to become readonly to the user, and this must be done on the client without a roundtrip to the server.

    I want to share with you and others the following solution that I came up with just a short while ago... This solution will work along with the styleset assigned to the control (if used) and will even properly utilize styles assigned to the disabled state if you have added such state style to your styleset css files (customized css).

    if (IwantToDisableCombo)
        EnableDisableCombo(_id, false);
    else
        EnableDisableCombo(_id, true);  


    // comboid:  the id of the webcombo (clientid) as seen by the browser in Javascript
    // state: whether you want to enable or disable the webcombo control.  Passing true Enables it, while passing false Disables it
    function EnableDisableCombo(comboid, state) {
        var _ctl = igcmbo_getComboById(comboid);
        if (_ctl) {
            if (state == true) {
                var _maindiv = $get(_ctl.ClientUniqueId + '_Main');
                if (_maindiv)
                    _maindiv.removeAttribute('disabled');
                var _inputctl = $get(_ctl.ClientUniqueId + '_input')
                if (_inputctl)
                    _inputctl.removeAttribute('disabled');
            }
            else {
                var _maindiv = $get(_ctl.ClientUniqueId + '_Main');
                if (_maindiv)
                    _maindiv.setAttribute('disabled', 'disabled');
                var _inputctl = $get(_ctl.ClientUniqueId + '_input')
                if (_inputctl)
                    _inputctl.setAttribute('disabled', 'disabled');
            }
        }
    };


    As you can see, I am searching for two items that are auto-generated at runtime by the control and sent to the browser.  These items are named using the webcombo's ClientUniqueId with either "_Main" or "_input" appended to it. As an example, if the webcombo control has the following ClientUniqueId "ctl00xContentPlaceHolder1xtabItemxctl00xxxctlx6" (mine is several layers down the hierarchy), then the html elements you are looking for have the following Ids "ctl00xContentPlaceHolder1xtabItemxctl00xxxctlx6_Main" and "ctl00xContentPlaceHolder1xtabItemxctl00xxxctlx6_input".  We only need to set or unset the disabled attributes on these elements and we have our intended behavior.


    I hope this helps

    Ali M

Children
No Data