473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Changing stylesheet rules

I have a calender control on my page. It is a popup control, meaning when I click on calender image then it opens up. But the problem is when I am changing the month, it becomes invisible due to stylesheet rule. which is following.

Expand|Select|Wrap|Line Numbers
  1. #datePicker
  2. {
  3.        display:none;
  4.        position:absolute;
  5.        border:solid 2px black;
  6.        background-color:white;
  7. }
  8.  
and the calender is following

Expand|Select|Wrap|Line Numbers
  1. <img src="Calendar.gif" onclick="displayCalendar()" />
  2.  
  3. <div id="datePicker">
  4.     <asp:Calendar
  5.         id="calEventDate"
  6.         OnSelectionChanged="calEventDate_SelectionChanged" 
  7.         Runat="server" />
  8.     </div>
  9.  
  10. function displayCalendar()
  11. {
  12.     var datePicker = document.getElementById('datePicker');
  13.     datePicker.style.display = 'block';
  14. }
  15.  
Can I change style sheet rule dynamically in the page load postback event, so when the month changes I can make display:"block" instead of "none".
Jul 1 '09 #1
4 2304
kunal pawar
297 100+
You can do one thing, create another CSS class for display image and assign that css class using javascript to datePicker
Jul 2 '09 #2
Frinavale
9,735 Expert Mod 8TB
Change the <div> that contains the Calendar into a Panel.

When the month is changed set the style of the panel to display:block.
You'll have to change your JavaScript so that it uses the Panel's ClientID. Sometimes when the Panel is rendered in the browser (as a <div>) it's given a different ID than the one you gave it in your .NET code. The reason is because the ID has to be unique....so if you're using MasterPages or User Controls this is changed in order to meet this requirement.

Please note that I'm using VB.NET in the following example...let me know if you're using C#...

Expand|Select|Wrap|Line Numbers
  1. <img src="Calendar.gif" onclick="displayCalendar()" />
  2.  
  3. <asp:Panel Id="datePicker" runat="server">
  4.     <asp:Calendar
  5.         id="calEventDate"
  6.         OnSelectionChanged="calEventDate_SelectionChanged" 
  7.         Runat="server" />
  8. </asp:Panel>
  9.  
  10. function displayCalendar()
  11. {
  12.     var datePicker = document.getElementById('<%= datePicker.ClientID %>');
  13.     datePicker.style.display = 'block';
  14. }
  15.  
In your .net code you'd have:

Expand|Select|Wrap|Line Numbers
  1. Private displayCalEventDate As Boolean = False 'indicates whether or not to display the panel containng the calendar on postback
  2.  
  3. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  4.  
  5.      If IsPostBack = True Then
  6.          'Retrieving whether or not to display the panel containing the calanedar
  7.          'from ViewState... it's saved there in the PreRender event.
  8.         displayCalEventDate = Ctype(ViewState("displayCalEventDate"), Boolean)
  9.     End If
  10.  
  11. End Sub
  12.  
  13. Protected Sub calEventDate_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles calEventDate.SelectionChanged
  14.     displayCalEventDate = True
  15. End Sub
  16.  
  17. Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
  18.    'The PreRender event happens just before the page is sent to the browser
  19.    'Here Check to see if the calendar's style should be changed to display
  20.    'And save the value for next time (I'm using ViewState here but you don't have to)
  21.  
  22.     ViewState("displayCalEventDate") = displayCalEventDate 
  23.     If displayCalEventDate Then
  24.       datePicker.style.Remove("display")
  25.       datePicker.style.Add("display", "block")
  26.    End If
  27. End Sub
Cheers!
-Frinny
Jul 2 '09 #3
This is what I have and it is working.

Expand|Select|Wrap|Line Numbers
  1. <img alt="" src="<%=Page.resolveUrl("~/images/Calendar.gif")%>" onclick="displayCalendar('startDate')" />
  2. <div id="startDate">
  3.     <asp:Calendar
  4.     id="calEventDate"
  5.     OnSelectionChanged="calEventDate_SelectionChanged" 
  6.     Runat="server" BackColor="#6DB523" BorderColor="#FFCC66" BorderWidth="1px" 
  7.     DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" 
  8.     ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px" >
  9.     <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
  10.     <SelectorStyle BackColor="#FFCC66" />
  11.     <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
  12.     <OtherMonthDayStyle ForeColor="white" />
  13.     <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
  14.     <DayHeaderStyle BackColor="#41498A" Font-Bold="True" Height="1px" ForeColor="White" />
  15.     <TitleStyle BackColor="#FC5B04" Font-Bold="True" Font-Size="9pt" 
  16.         ForeColor="#FFFFCC" />
  17.     </asp:Calendar>
  18. </div>
  19.  
  20. <img alt="" src="<%=Page.resolveUrl("~/images/Calendar.gif")%>" onclick="displayCalendar('endDate')" />
  21. <div id="endDate">
  22.     <asp:Calendar
  23.     id="calEndDate"
  24.     OnSelectionChanged="calEventDate_SelectionChanged" 
  25.     Runat="server" BackColor="#6DB523" BorderColor="#FFCC66" BorderWidth="1px" 
  26.     DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" 
  27.     ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px" >
  28.     <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
  29.     <SelectorStyle BackColor="#FFCC66" />
  30.     <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
  31.     <OtherMonthDayStyle ForeColor="white" />
  32.     <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
  33.     <DayHeaderStyle BackColor="#41498A" Font-Bold="True" Height="1px" ForeColor="White" />
  34.     <TitleStyle BackColor="#FC5B04" Font-Bold="True" Font-Size="9pt" 
  35.         ForeColor="#FFFFCC" />
  36.     </asp:Calendar>
  37. </div>
  38.  
  39. <!-- Following conditional statement is used to check which calender month was changed -->
  40. <%
  41.     If Session("calName") = "calEndDate" Then
  42. %>        
  43.     <script type="text/javascript">
  44.         var datePicker = document.getElementById("endDate");
  45.         datePicker.style.display = "block";
  46.     </script>
  47. <%  
  48. ElseIf Session("calName") = "calStartDate" Then
  49. %>        
  50.     <script type="text/javascript">
  51.         var datePicker = document.getElementById("startDate");
  52.         datePicker.style.display = "block";
  53.     </script>
  54. <% 
  55.    End If
  56. %> 
  57.  
  58. <!-- This is what I have in vb file -->
  59.  
  60. Protected Sub calEndDate_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles calEndDate.VisibleMonthChanged
  61.     Session("calName") = "calEndDate"
  62. End Sub
  63.  
  64. Protected Sub calEventDate_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles calEventDate.VisibleMonthChanged
  65.     Session("calName") = "calStartDate"
  66. End Sub
  67.  
And this is in the javascript

Expand|Select|Wrap|Line Numbers
  1. function displayCalendar(calID) {
  2.     var datePicker = document.getElementById(calID);
  3.     var notClickedCalenderName = (calID == "startDate" ? notClickedCalenderName = "endDate" : notClickedCalenderName = "startDate");
  4.     var notClickedCalender = document.getElementById(notClickedCalenderName);
  5.  
  6.     if (datePicker.style.display.indexOf("block") > -1) {
  7.         datePicker.style.display = 'none';
  8.     }
  9.     else {
  10.         datePicker.style.display = 'block';
  11.         notClickedCalender.style.display = 'none';
  12.     } 
  13. }
  14.  
Please let me know if there is difference in our approach.
Jul 2 '09 #4
Frinavale
9,735 Expert Mod 8TB
Well that works too :)
My solution uses less JavaScript than yours does but both will get the job done :)
Jul 2 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jeff Thies | last post by:
I have a number of elements of "some-class". I'd like to change the styles of some-class: from ..some-class{color: red; display: block} to
1
by: Raghuram Banda | last post by:
Hi all, I've created a table with Table Header and the table may or may not contain any rows initially. I've included a .css file in <head> section of my HTML script and I'm creating rows to...
6
by: Jacqueline | last post by:
Hi, I would like to be able to write some code in Javascript preferably (PHP is also all right) which allows the admin of a website to be able to change stylesheet attributes from a GUI browser...
5
by: Andrew Poulos | last post by:
I'm trying to change a style in a stylesheet. The following code works in FF, MZ, and IE6 but IE 5 gives the error of "invalid procedure call or argument": var oStyleSheet =...
2
by: Valerian John | last post by:
Hi, folks: I am looking for a way to switch stylesheets for our webforms. We want to have a default stylesheet and then allow the user to pick from a list of pre-defined stylesheets. The user's...
0
by: RAM | last post by:
Hello, I am learning .NET 2.0. I have written simple ASP.NETapplication. I would like to change password rules, so I added to web.config: <membership...
1
by: Jeff | last post by:
Often, a page will have more than one stylesheet. Some external and some embedded. If there are multiple rules that have *identical* selectors, will the last one always take precedence? Any...
1
by: Shalini Bhalla | last post by:
How can I modify external stylesheet by valuses i m getting from any oher page <style type="text/css"> .heading { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px;...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.