how to send data into function using onclientselectedindexchanged

6 posts, 0 answers
  1. Doug
    Doug avatar
    70 posts
    Member since:
    Aug 2014

    Posted 16 Jun Link to this post

    oComboBox.OnClientSelectedIndexChanged = "ShowHideTextbox('" & oComboBox.ClientID & "','" & oTextbox.ClientID & "','" & oLabel.ClientID & "')"

    ^ doesn't work and I see on API I should just have a function name there such as this?
    oComboBox.OnClientSelectedIndexChanged = "ShowHideTextbox"

    inside my js function I see I can do this
     var item = eventArgs.get_item();

    but how can I assign my 3 values into arguments called into the function?
  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 17 Jun Link to this post

    Hello Doug,

    Here's how you can send additional data as parameters and access the data in the ComboBox' OnClientSelectedIndexChanged client-side event handler:
    protected void Page_Load(object sender, EventArgs e)
    {
        string myParameter1 = "Value1";
        string myParameter2 = "Value2";
        string myParameter3 = "Value3";
        oComboBox.OnClientSelectedIndexChanged = "function(sender, args){ShowHideTextbox(sender, args, '" + myParameter1 + "'" + ", '" + myParameter2 + "'" + ", '" + myParameter3 + "');}";
    }

    function ShowHideTextbox(sender, args, param1, param2, param3) {
        // access param1, 2, 3...
    }


    Regards,
    Ivan Danchev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Doug
    Doug avatar
    70 posts
    Member since:
    Aug 2014

    Posted 17 Jun in reply to Ivan Danchev Link to this post

    I used the wrong caller as I am using checkboxes so I changed it to .OnClientItemChecked
  5. Doug
    Doug avatar
    70 posts
    Member since:
    Aug 2014

    Posted 17 Jun in reply to Doug Link to this post

    I can only get this to half work.
    I have to iterate through checkboxes, find "Other" one and see if it is checked and then show / hide an input.

    I searched your sample code to loop the combobox checkboxes and could not get any of the functions to work. but it may also be the same issue that I did get working.
    anyhow here is the code that works when called on page load (not from the combobox itself) to init my hide/show. <-- this code works

    function ShowHideTextbox(sender, args, oDropID, oTextID, oLabelID) {
     
        //var ddl = document.getElementById(oDropID);
     
        var oTextbox = document.getElementById(oTextID);
        var oLabel = document.getElementById(oLabelID);
        var bShow = false;
     
        $('#' + oDropID + ' INPUT').each(function () {
           // alert(this);
            if (this.type == "checkbox") {
                if (this.checked) {
                    var sText = this.nextSibling.data;
                    if (sText == "Other") bShow = true;
                }
            }
        });
        if (bShow) {
            oLabel.style.display = 'inline';
            oTextbox.style.display = 'inline';
            oTextbox.focus();
        } else {
            oLabel.style.display = 'none';
            oTextbox.style.display = 'none';
        }
    }

     

    but when this is called from the combobox using the .OnClientItemChecked there are only 2 items in this loop (text + hidden)

    it is like the div isn't built out yet. is it calling it too soon to loop the items?

    I have verified both calling from page load and combobox sends in the same values.

  6. Doug
    Doug avatar
    70 posts
    Member since:
    Aug 2014

    Posted 17 Jun in reply to Doug Link to this post

    ok I search the page source and see the div name that has my checkboxes added _DropDown to the name so I changed it to
    $('#' + oDropID + '_DropDown INPUT').each(function () {

    ^ this works for me
  7. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 20 Jun Link to this post

    Hello Doug,

    I am glad passing additional data to the OnClientItemChecked handler worked as expected and you were able to access the checkboxes with the modified selector.

    Regards,
    Ivan Danchev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017