473,792 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Javascript with ASP.NET Dropdown Control

Hello All:

I hava a ASP.NET Web Page where I want to change the visibility of a
Dropdown, I want to avoid using Postback
since the selection of the Dropdown choices is always the same. The Code
below is just a date filter selection.

The Code works fine but on page postback I want to reload the Js script so
the Dropdown visibility selection remains.

--- JS ---

<script>
function FilterStatus()
{
var drpFilterType = document.getEle mentById("drpFi lterType");
var selectedFilterT ype = drpFilterType
..options[drpFilterType.s electedIndex].value;
if (selectedFilter Type == "MonthFilte r")
{
document.getEle mentById("drpMo nthFilter").sty le.visibility=" visible";
document.getEle mentById("drpYe arFilter").styl e.visibility="v isible";
}
else if (selectedFilter Type == "YearFilter ")
{
document.getEle mentById("drpMo nthFilter").sty le.visibility=" hidden";
document.getEle mentById("drpYe arFilter").styl e.visibility="v isible";
}
else if (selectedFilter Type == "All")
{
document.getEle mentById("drpMo nthFilter").sty le.visibility=" hidden";
document.getEle mentById("drpYe arFilter").styl e.visibility="h idden";
}
}
</script>
-- ASP.NET Page --

Filter Type
<asp:dropdownli st id="drpFilterTy pe" runat="server" CssClass="boxfo rmwh"
onchange="retur n FilterStatus()" >
<asp:ListItem Value="MonthFil ter">Month</asp:ListItem>
<asp:ListItem Value="YearFilt er">Year</asp:ListItem>
<asp:ListItem Value="All">All Data</asp:ListItem>
</asp:dropdownlis t>
<asp:dropdownli st id="drpMonthFil ter" runat="server"
style="visibili ty:visible;" /></td>
<asp:dropdownli st id="drpYearFilt er" runat="server"
style="visibili ty:visible;"/>
<asp:button id="btnFilterDa ta" runat="server" CssClass="Butto n" Text="Filter
Data"></asp:button>



Dec 14 '05 #1
1 2095
Nice code... except it's <script type="text/javascript"></script> (and
see my below note about the deprecated visibility attribute)

Here's what I would do...

var viewStatus = (<asp:Literal id="litViewStat us"
runat="server"> </asp:Literal>) ? "block" : "none";

Then

myContainer.sty le.display = viewStatus;
(or combine the two)

Don't use "visibility ", that's been deprecated for a number of years.
You use "display" with many options but here are the most common:

none - don't show
inline - inline page flow (the default for span and most other things
block - newline page flow (the default for div)

I would do something like this...

<div id="myContainer ">
<asp:DropDownLi st>...
</div>

and then play with the method I just gave you. (you're also want to
avoid the use of style="" as that defeats the point of CSS: to be a
page's presentation codehind) You can use the above method to also
just write an inline CSS page. like this

#myContainer {
display: <asp:Literal id="litViewStat us"
runat="server"> </asp:Literal>);
}

Which actually seems nicer...just make sure you do something with
litViewStatus in you .NET codebehind.

--
David Betz
http://www.davidbetz.net/winfx/
http://www.davidbetz.net/dynamicbliss/

Dec 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10761
by: Robert Mark Bram | last post by:
Hi All! Has anyone seen an example of the following javascript powered control: - a dropdown select menu - the width of the control is set. Assume by "control" I mean the visible part of the drop down before a mouse click occurs. - the width of the list when selected is dynamic - the width of the list can grow beyond the width of the control without changing the width of the control.
10
2266
by: Paul | last post by:
Hi I am using the HtmlInputFile control to upload a file from a client to a server. I have a browse to find the file on the server but need to create the path dynamically as to were it will go based on some dropdown boxes, one for the year and one for the month. This line saves the file so I am trying to get the month and year from the dropdown boxes and put them in the month and year variables but this does not work,...
1
2474
by: AndiSmith | last post by:
Hi guys, I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based website. I've created an AJAX based user control, which is dynamically placed on a page (once, or multiple times) if the user has the correct permissions to receive it. It contains two drop down lists - employee value and partner value; and a...
7
33872
by: =?Utf-8?B?Qw==?= | last post by:
I have a dropdown list as below. I add an onchnage attribute in my codebehind to call some Javascript. I want to get the selected text from my dropdown. What am I doing wrong below? <asp:DropDownList ID="ddlStatus" runat="server" /> In my codebehind
2
9140
by: wildman | last post by:
RE: Gridview textbox has data check without postback.. javascript? I have a gridview with a textbox. I can set the textbox to autopostback and check for a value in a prerender event to decide if I should make a button on the grid row visible. However, the problem with autopostback on a textbox is the postback occurrs when you select another control or click away ( I guess). This is very awkward when the control selected is dropdown as...
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.