none
Jquery based UserControl Webpart returns null values RRS feed

  • Question

  • Hi,

    I have a user control webpart in SP 2013(and was working absolutely fine in SP 2010) now its returning null for the checkbox and radio button combination if I read from .cs file:

    Request.Form["txtIndustry"].ToString() Like the image below there are almost 20-30 various options.

    Here is the .ascx file code

     $(document).ready(function () {             
         
            $(".divIndustrySubSelect").css("display", "none");
            $('#divIndustries :checkbox').click(function () {
                var allIndustryVals = [];
                var nbrIndustry = $("#divIndustries :checkbox:checked").length;

                if ($(this).parent('div').find('input:first').is(':checked')) {
                    $(this).parent('div').children('.divIndustrySubSelect').show();
                }
                else {
                    $(this).parent('div').children('.divIndustrySubSelect').hide();
                }

                $('#divIndustries :checkbox:checked').each(function () {
                    allIndustryVals.push($(this).next().text());
                });

                if (nbrIndustry > 0) {
                    $("#divIndustriesParent").find("span").text(' (' + allIndustryVals + ' )');
                    $("#txtIndustry").val(allIndustryVals);
                }
                else {
                    $("#divIndustriesParent").find("span").text('');
                    $("#txtIndustry").val('');
                }
            });
            $('.divIndustrySubSelect :radio').click(function () {
                var allIndustryVals = [];
                var sParentIndustry = $(this).parents('div').eq(1).find(' :checkbox:first').next().text();
                $(this).parents('div').eq(1).find('input:first').val(sParentIndustry + ';' + $(this).val());
                $('#divIndustries :checkbox:checked').each(function () {
                    allIndustryVals.push($(this).val());
                });
                $("#txtIndustry").val(allIndustryVals);
            });

    }

    // recover the state of the controls

            var sIndustry = '<%=Request.Form["txtIndustry"] %>';
            var arrayIndustry = sIndustry.split(",");
            $('#divIndustries :checkbox').each(function () {
                if ($.inArray($(this).next().text(), arrayIndustry) > -1) {
                    $(this).attr('checked', true).click().attr('checked', true);
                    $("#divIndustries").show();
                }
            });

    //Rendering UI

    <div id="divIndustriesParent">
     <a href="#">Industry<span></span></a></div>
     <div id="divIndustries" class="inside">        
            <%= RenderIndustries() %>
    </div>

    //Hidden field used by code-behind

    <input id="txtIndustry" name="txtIndustry" visible="true" />

    Will you please assist me if there is any Jquery depreciated functions?

    Many Thanks

    Shri

    Friday, March 3, 2017 1:55 AM

All replies

  • Any assistance please?

    Thanks

    Friday, March 3, 2017 8:00 PM
  • Hi ShriG,

    To narrow down the Jquery error, I would suggest you can use IE developer tool to trace it. Then, please post the error message so that it could easier to find the solution.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, March 6, 2017 7:36 AM
  • I wonder if it's your checkbox and radio selectors? https://api.jquery.com/checkbox-selector/
    Monday, March 6, 2017 7:42 AM
  • Here is the screenshot during debug:

    Monday, March 6, 2017 5:35 PM
  • The error is SyntaxError. function push(native code) is where throwing errors. querySelectorAll(x)

    Any ideas?

    Monday, March 6, 2017 5:39 PM
  • Its not the error its throwing. I verified using Google Chrome debugging. It captures the values correctly. There is absolutely no errors for the full lifecycle. can you please let me know if there is anything I have to change? It doesn't return any value from .cs file
    Tuesday, March 7, 2017 1:49 AM