set the visibility of text box to false when the rad combo box shows empty message string

1.2k Views Asked by At

I have a user control in which am using one editable rad combo and one rad text box. depends on the value of combo i need to set the visibility of text box. its working. the code is as follows.
1. User Control

<asp:Panel ID="pnl44" runat="server" Visible="false">
    <table width="100%">
        <tr>
            <td style="width: 20%;">
                Quantity<span style='color: red'>* </span>
            </td>
            <td align="left" style="vertical-align: top; width: 80%;">
                <table width="100%">
                    <tr>
                        <td align="left" style="vertical-align: top; width: 63%;">
                            <telerik:RadComboBox ID="pnl44_ddlUnit" runat="server" DropDownAutoWidth="Enabled" 
                             Width="150px" AutoPostBack="true" OnSelectedIndexChanged="ddlUnit_SelectedIndexChanged" 
                             EmptyMessage="---Select---" markfirstmatch="True" allowcustomtext="false" onclientblur="OnClientBlurHandler"></telerik:RadComboBox>
                        </td>
                        <td>
                            <asp:TextBox ID="pnl44_txtQuantity" MaxLength="10" runat="server" CssClass="textfield"
                                Width="145px"  />
                            <ajaxtoolkit:FilteredTextBoxExtender ID="ftetxtQuantity" FilterType="Numbers" runat="server"
                                TargetControlID="pnl44_txtQuantity" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Panel>

in the code behind am handling the selected changed event to set the visibility, its working fine. the javascript for on blur is as follows (it is in the aspx page).

<script type="text/javascript" language="javascript">   
        function OnClientBlurHandler(sender) {                                                                                  
            var item = sender.findItemByText(sender.get_text());
            if (!item) {
                sender.clearSelection();
            }

        }
    </script>

with this whenever the combo value is null, it will show the empty message.

the scenario is like this

by default the visibility of txtQuantity is false. when user select 'value1' from combo, the txtQuantity visibility is true; then the user is deleting value1 using delete/backspace, combo box will show empty message string, but that time the txtQuantity visibility is true, instead false.

please help me to solve the issue...

1

There are 1 best solutions below

1
On BEST ANSWER

It seems you change the textbox visibility on the server, so you would need to initiate a request that will do that for you when you clear the combo selection. Basics:

    function OnClientBlurHandler(sender) {                                                                                  
        var item = sender.findItemByText(sender.get_text());
        if (!item) {
            sender.clearSelection();
            __doPostBack("", "");
        }

    }

which will generate a generic postback. You can use hidden buttons or hidden fields or other arguments to know where this postback originated from.

Option 2: hide the textbox with JavaScript, e.g.:

    function OnClientBlurHandler(sender) {                                                                                  
        var item = sender.findItemByText(sender.get_text());
        if (!item) {
            sender.clearSelection();
            document.getElementById("<%=pnl44_txtQuantity.ClientID%>").style.display="none";
        }
    }

or something similar, depending on what the ACT control does with the textbox.