views:

291

answers:

3
<asp:DropDownList ID="ddloption" runat="server" Visible="false">
  <asp:ListItem Text="Active" Value="Active"></asp:ListItem>
  <asp:ListItem Text="D-Active" Value="D-Active"></asp:ListItem>
</asp:DropDownList>

function boxchange(dd)
{
  document.getElementById("<%= ddloption.ClientID%>").visibility = "visible";
}

ddloption is null, what i m getting...can you tell me how to work with this.

A: 

try

 function boxchange(dd)
 {
    var control = document.getElementById("<%= ddloption.ClientID %>");
    if (control != null)
       control.style.visibility = "visible";
 }

Nick is right, didn't even notice.

gg
+1  A: 

When you have a runat="server" visible="false" asp control, it is not rendered in the html. Try something like this:

<div id="wrapper" style="display: none;">
    <asp:DropDownList ID="ddloption" runat="server">
        <asp:ListItem Text="Active" Value="Active"></asp:ListItem>
        <asp:ListItem Text="D-Active" Value="D-Active"></asp:ListItem>
    </asp:DropDownList>
</div>


function boxchange(dd)
    {
          document.getElementById("wrapper").style.display = "block";
    }
Nick Spiers
hey i wrote the same in my code but it's not working and not giving any error...what can be the reason?
hmm.. not sure, it works in my sample page. You sure you didn't miss anything? removing the visible="false" from ddloption?
Nick Spiers
yes i remove the tag visible="false"...thaks for help.
hey it wokrd...
+1  A: 

To hide the dropdown

  document.getElementById("<%= ddloption.ClientID%>").Style.display='none';

To Show it again:

document.getElementById("<%= ddloption.ClientID%>").Style.display='';

Cheers

Anthony