This is a migrated thread and some comments may be shown as answers.

Client side function not working when combo box auto postback time

6 Answers 168 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Prassin
Top achievements
Rank 1
Prassin asked on 28 Jul 2012, 10:38 AM
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

6 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 01 Aug 2012, 02:28 PM
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.
0
Prassin
Top achievements
Rank 1
answered on 03 Aug 2012, 06:03 AM
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 
0
Princy
Top achievements
Rank 2
answered on 03 Aug 2012, 10:51 AM
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.
0
Prassin
Top achievements
Rank 1
answered on 03 Aug 2012, 11:55 AM
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
0
Princy
Top achievements
Rank 2
answered on 06 Aug 2012, 05:49 AM
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.
0
Prassin
Top achievements
Rank 1
answered on 06 Aug 2012, 06:17 AM
Princy,

Thanks. its working

Regards,
Prassin
Tags
ComboBox
Asked by
Prassin
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Prassin
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or