473,657 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing stylesheet rules

84 New Member
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 2319
kunal pawar
297 Contributor
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 Recognized Expert Moderator Expert
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
programmerboy
84 New Member
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 Recognized Expert Moderator Expert
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
10335
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
3590
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 the table dynamically using JavaScript (using DOM), and the problem is those created bby DOM are not following style sheet rules applicable for table rows and cells. But the rows created from within
6
3153
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 interface without having them to change the text file themselves. (i.e., working on the supposition that the admin is IT illiterate). Simple things like table heading colours, backgrounds, font sizes need to be changed this way.
5
1545
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 = window.document.styleSheets.imports; oStyleSheet.addRule("td","font-size:1.2em;"); Is there a way to do this with IE 5? Andrew Poulos
2
1110
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 choice will be stored in the database in the user's profile and all the pages/webforms must use the user's stylesheet selection. TIA, Val
0
1064
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 defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="20"> <providers>
1
2047
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 known instances where this is not true? #section_1 DIV{color: red} ^^^^^^^^^^^^^^ By selector I meant that part. And I mean identical selectors.
1
1202
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; color: #666699; text-decoration: none; font-style: normal; font-weight: bolder;
6
2550
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
1
8503
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
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
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
6167
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
5632
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.