The easiest / best hide / show client side Hide / show for ASP.NET

I have a DropDownList and TextBox on the page. When the user selects the “other” option in DropDownList, I want to display the TextBox right to his right. I do not want to use the traditional PostBack technique. I want this interaction to be on the client side.

I know that I can get a reference to a DOM element and set its style to "display: none" or "display:". I am looking for something that is built into the ASP.NET framework to handle something like that. I mean, in jQuery it is as simple as $('controlID').hide. Is there a control expander that can do this? Is jQuery part of the ASP.NET framework?

+3
source share
2 answers

jQuery will / be distributed using VisualStudio / ASP.NET MVC , although I would not call it part of the framework. I think you can freely use it and hope that it will be supported.

Please note that Microsoft has stated that it will use the main development line for jQuery, so the code itself will not differ from the one you can download from jQuery.com, with the possible exception of the built-in Intellisense.

EDIT. , jquery.com. javascript. script . jquery, onchange , - , , . , other . runat = "server" MasterPages UserControls, javascript , ASP.NET. , CSS , ".class", "#id".

<script type="text/javascript" src="...pathtoscript../jquery.1.2.6.js"></script>
<script type="text/javascript">
   $(document).ready( function() {
       $("#DropDownListID").bind('change', function() {
           if (this.options[this.selectedIndex].value == 'other')
           {
               $("#TextBoxID").show();
           }
           else
           {
               $("#TextBoxID").hide();
           }
       });
   });
</script>

  ...

 <select id="DropDownList">
     <option value='first'>First</option>
      ...
     <option value='other'>Other</option>
 </select>
 <input type='text' id='TextBox' style='display: none;' />
+4

asp.net( scriptmanager), . DOM.

$get('<%= myDropDown.ClientID %>').style.display = 'none';

, script.

- , , jquery, , , ; -)

+2

All Articles