Q:

Show hide Textbox based on radio button list value

I would like to hide txtsearch when the RadioButtonListvalue = OrderDate to hide txtsearch and show txtsearch if any other value is selected 
I tried the code below it didn't work 
if (!IsPostBack)
{
    if (lblfield.SelectedValue == "OrderDate")
    {
         txtsearch.Visible = false;
    }
    else
    {
         txtsearch.Visible = true;
    }
}

<asp:RadioButtonList ID="lblfield" runat="server" CellPadding="10" CellSpacing="10" RepeatDirection="Horizontal" AutoPostBack="true" Width="460px">
       <asp:ListItem Selected="True" Value="Cust_Name">Customer</asp:ListItem>
       <asp:ListItem Value="OrderDate">Order Date</asp:ListItem>
       <asp:ListItem Value="TotalAmount">Total Amount</asp:ListItem>
       <asp:ListItem Value="InvoiceStatus">Invoice Status</asp:ListItem>
 </asp:RadioButtonList>

 <asp:TextBox ID="txtsearch" runat="server" class="form-control" placeholder="Search"></asp:TextBox>

A:

You don't need to use if (!IsPostBack). Just remove if (!IsPostBack) and then code works fine.
protected void Page_Load(object sender, EventArgs e)
{

     if (lblfield.SelectedValue == "OrderDate")
     {
          txtsearch.Visible = false;
     }

     else
     {
          txtsearch.Visible = true;
     }
}

Or just in one line:
txtsearch.Visible = lblfield.SelectedValue == "OrderDate" ? false : true;

