Search code examples
c#asp.netradio-buttonraddatepicker

Enable/Disable RadDatePicker on Radio Button Checked


I'm having a bit of a problem regarding RadioButton CheckedChanged. I have three radio buttons, a RadDatePicker, a textbox and a button. I'm simply trying to search data using the value given in the textbox depending on the Radio Button selected. My problem is with the third Radio Button, which is "dateCreated". I want to make the RadDatePicker enabled when the third Radio Button is selected. I also need to do this in code behind and not using Javascript or any other method. Please Help.

Here's my code :

.aspx

<table>
    <tr>
        <td style="font-family: Calibri; font-weight: 400; font-style: normal; text-transform: none; color: #FFFFFF;" colspan="2">
            &nbsp;
        </td>

        <td class="style19" align="left" colspan="2" style="font-family: Calibri; font-weight: 400; font-style: normal; text-transform: none; color: #FFFFFF">
            <asp:Label ID="searchTitle" runat="server" CssClass="style47" Font-Bold="False" Font-Names="Traditional Arabic" Font-Size="Medium" Font-Strikeout="False" ForeColor="#006699" Style="font-size: x-large; font-family: 'Myriad Pro'" Text="Search Non-Disclosure Document"></asp:Label>
        </td>
    </tr>
</table>

<table style="font-family: Calibri">
    <tr>
        <td class="style75">

        </td>
    </tr>

    <tr>
        <td class="style81">

        </td>

        <td class="style84">

        </td>

        <tr>
            <td bgcolor="#EEF4FD" class="style77">
                <asp:Label ID="ndaSearchTitle" runat="server" Text="Search NDA by :"></asp:Label>
            </td>

            <td bgcolor="#EEF4FD" class="style87">
            </td>

            <td bgcolor="#EEF4FD" class="style83">
                <asp:RadioButton ID="nameSearch" runat="server" Checked="true" GroupName="searchRad" Text="Company Name" />
            </td>
        </tr>

        <tr>
            <td bgcolor="#EEF4FD" class="style77">
            </td>

            <td bgcolor="#EEF4FD" class="style87">
            </td>

            <td bgcolor="#EEF4FD" class="style83">
                <asp:RadioButton ID="countrySearch" runat="server" GroupName="searchRad" Text="Country Incorperated" />
            </td>
        </tr>

        <tr>
            <td bgcolor="#EEF4FD" class="style77">
            </td>

            <td bgcolor="#EEF4FD" class="style87">
            </td>

            <td bgcolor="#EEF4FD" class="style83">
                <asp:RadioButton ID="dateSearch" runat="server" GroupName="searchRad" Text="Date Created" oncheckedchanged="dateSearch_CheckedChanged" />

                <telerik:RadDatePicker ID="RadDatePicker2" runat="server" 
                                DateInput-DateFormat="dd-MM-yyyy" Skin="Default" style="margin-left: 0px" Width="45%" Enabled="false">
                </telerik:RadDatePicker>
            </td>
        </tr>

        <tr>
            <td bgcolor="#93B4DF" class="style3" colspan="3" style="font-family: Calibri; font-size: large; font-weight: normal; height:20px;">
            </td>
        </tr>

        <tr>
            <td bgcolor="#EEF4FD" class="style77">
            </td>

            <td bgcolor="#EEF4FD" class="style87">
            </td>

            <td bgcolor="#EEF4FD" class="style83">
                <asp:TextBox ID="ndaSearchBox" runat="server" Width="350px"></asp:TextBox>
                &nbsp;&nbsp;
                <asp:Button ID="btnSearch" runat="server" Text="Search" />
            </td>
        </tr>
    </tr>
</table>

aspx.cs

protected void dateSearch_CheckedChanged(object sender, EventArgs e)
{
    if (dateSearch.Checked == true)
    {
        RadDatePicker2.Enabled = true;
    }

    else
    {
        RadDatePicker2.Enabled = false;
    }
}

Solution

  • try adding autopostback attribute alos

     <asp:RadioButton ID="dateSearch" runat="server" GroupName="searchRad" Text="Date Created" oncheckedchanged="dateSearch_CheckedChanged" autopostback="true" />