Client side function not working when combo box auto postback time

7 posts, 0 answers
  1. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 28 Jul 2012 Link to this post

    Hi all,, 

    I have a check box and 3 combo box.. when the check box checked that time only the combo box state change to enable.. when check box state is false combo gone disabled.. this validation work at client side 

    Script
    <script type="text/javascript" language="javascript">
            function EnableControl_3() {
                var combo3 = $find("<%= RadCmbxSections.ClientID %>");
                var combo4 = $find("<%= RadCmbxDepartment.ClientID %>");
                var combo = $find("<%= RadCmbxEmployee.ClientID %>");
     
                var checkbox = document.getElementById('<%= chkEmployee.ClientID %>');
                if (checkbox.checked) {
                    combo.enable();
     
                    combo3.enable();
                    combo4.enable();
                } else {
                    combo.disable();
     
                    combo3.disable();
                    combo4.disable();
                }
            }
        </script>

    Aspx
    <telerik:RadComboBox runat="server" ID="RadCmbxEmployee" Height="190px" EmptyMessage="Select supplier"
                                                                Width="410px" MarkFirstMatch="true" DataSourceID="SqlDataSource2" EnableLoadOnDemand="true"
                                                                HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
                                                                OnDataBound="RadCmbxEmployee_DataBound" OnItemDataBound="RadCmbxEmployee_ItemDataBound"
                                                                OnItemsRequested="RadCmbxEmployee_ItemsRequested" AutoPostBack="True">
                                                                <HeaderTemplate>
                                                                    <ul class="rcbHovered">
                                                                        <li class="col1">Name</li>
                                                                        <li class="col2">Code</li>
                                                                        <li class="col3">ContactPerson</li>
                                                                    </ul>
                                                                </HeaderTemplate>
                                                                <ItemTemplate>
                                                                    <ul>
                                                                        <li class="col1">
                                                                            <%#DataBinder.Eval(Container.DataItem, "Name")%></li>
                                                                        <li class="col2">
                                                                            <%#DataBinder.Eval(Container.DataItem, "Code")%></li>
                                                                        <li class="col3">
                                                                            <%#DataBinder.Eval(Container.DataItem, "ContactPerson")%></li>
                                                                    </ul>
                                                                </ItemTemplate>
                                                                <FooterTemplate>
                                                                    A total of
                                                                    <asp:Literal runat="server" ID="RadComboItemsCount" />
                                                                    items
                                                                </FooterTemplate>
                                                            </telerik:RadComboBox>

    Combo box auto post back is true..
    when i try to select a row of that combo box the combo box state changed to disable automatically.. 
    but still the check box state has been checked.. why this happen like this..

    Regards,

    Prassin
  2. Nencho
    Admin
    Nencho avatar
    1796 posts

    Posted 01 Aug 2012 Link to this post

    Hello Prassin,

    Could you clarify when exactly the EnableControl_3()function is being invoked ?

    Kind regards,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 03 Aug 2012 Link to this post

    Hi Nencho,


    <asp:CheckBox ID="chkEmployee" runat="server"  onclick="EnableControl_3();"
      Text="Employee" Font-Bold="True">
    </asp:CheckBox>


    The function  EnableControl_3() working regarding the checkbox checked change event.. by default all controls were disable. when check box checked change=true that time only the controls state change to enable by using this java script.. 
    here the problem is when the check box got checked that time the RadCmbxEmployee  and other combo box state change to enable... other combo boxes populate data regarding the RadCmbxEmployee selected index change event..
    so the RadCmbxEmployee combo box postback i turn to true.. when the event occur time (selected index change event) all controls state changed to disabled.. but the main thing is check box checked was not changed its state true only..
    why happen like this,, is there any changes needed for that javascript?
    Please help

    Regards,

    Prassin 
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Aug 2012 Link to this post

    Hi Prassin,

    Instead of making comboboxes disabled by default you can call the javascript function on pageLoad to disable the comboboxes if the checkbox is not checked.

    Javascript:
    <script type="text/javascript">
    function pageLoad()
    {
     EnableControl_3();
    }
    </script>

    Hope this helps.

    Thanks,
    Princy.
  5. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 03 Aug 2012 Link to this post

    Hi Princy,

    I tried like this

    <script type="text/javascript" language="javascript">
           function pageLoad() {
               function EnableControl_3() {
                   var combo3 = $find("<%= RadCmbxSections.ClientID %>");
                   var combo4 = $find("<%= RadCmbxDepartment.ClientID %>");
                   var combo = $find("<%= RadCmbxEmployee.ClientID %>");
     
                   var checkbox = document.getElementById('<%= chkEmployee.ClientID %>');
                   if (checkbox.checked) {
                       combo.enable();
     
                       combo3.enable();
                       combo4.enable();
                   } else {
                       combo.disable();
     
                       combo3.disable();
                       combo4.disable();
                   }
               }
           }
       </script>

    but its shown an error like "Microsoft JScript runtime error: 'EnableControl_3' is undefined"

    Regards,

    Prassin
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Aug 2012 Link to this post

    Hi Prassin,

    Here is the code that I tried based on your scenario which works as expected at my end. Please modify your code as follows.

    Javascript:
    <script type="text/javascript">
      function EnableControl_3()
      {
       var combo = $find("<%= RadCmbxEmployee.ClientID %>");
       var checkbox = $find('<%= chkEmployee.ClientID %>');
       var combo3 = $find("<%= RadCmbxSections.ClientID %>");
       var checkbox = document.getElementById('<%= chkEmployee.ClientID %>');
       if (checkbox.checked)
       {
        combo.enable();
        combo3.enable();
        combo4.enable();
       } else
       {
        combo.disable();
        combo3.disable();
        combo4.disable();
       }
     }
     function pageLoad()
     {
      EnableControl_3();
     }
    </script>

    Thanks,
    Princy.
  7. Prassin
    Prassin avatar
    87 posts
    Member since:
    Jun 2012

    Posted 06 Aug 2012 Link to this post

    Princy,

    Thanks. its working

    Regards,
    Prassin
Back to Top