This method allows you to show/hide a form element without making another request against the server. It also works when the show/hide element is required by the asp.net code behind.
You can use any type of sub element under a dropdown with this script. You will need to use a CDN or download and host your own jquery-1.3.2.min.js file.
SCRIPT
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script> <script type="text/javascript"> $(function() { $('#<%= Dropdown1.ClientID %>').change(function() { if (this.value=="My Value") { $('#<%= Element1.ClientID %> ').css({ visibility: 'visible' }); } else { $('#<%= Element1.ClientID %> ').css({ visibility: 'hidden' }); }}); }); </script>
HTML
<asp:DropDownList runat="server" ID="Dropdown1" class="required" >
<asp:ListItem Value=""> none</asp:ListItem>
<asp:ListItem Value="My Value">Some Text Here</asp:ListItem>
</asp:DropDownList>
<!-- place any element here with id="Element1" -->
If you are getting this error:
Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
First check that you have Microsoft.Web.Extensions.dll and Microsoft.Web.Extensions.Design.dll in your bin folder. Also check that you are using the correct version of .net in IIS.
If non of these solutions work then verify that if application is in a folder other than root you make this folder an application in IIS. Right click folder "convert to application".
First thing you will need to do is specify the scripting language, content type and endcoding type in a page element. Language will be visual Basic, content Type will be text/html and ecoding will be UTF-8
Next you will want to specify the doctype, this will tell the browser exactly what type of HTML you are using in the page. We'll be using the following DTD HTML doc type.
Now we need to import the System.Web.Mail asp.net namespace for use with our basic contact form
Now that the page basics are setup we need to write some script that will handle the information browsers will provide when visiting your page. First you need to write the server side script call. Then include a runat="server" verable which will tell the server to run it locally on the server side so the browser cannot view the information. This is done to prevent souce view bots from gaining email address information in your contact form.
Server side code
then you need to end the runat=server code
add standard HTML elements
Now the form, form fields and content
You may want to add some validation to the above code in order to prevent bots from filling out your contact form.
Finally closing of page HTML elements