Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove Hyperlink from ASP.NET Calendar

Posted on 2008-06-13
10
Medium Priority
?
2,795 Views
Last Modified: 2012-06-27
I have an ASP.Net Calendar. I'd like the Calendar to display the dates without the hyperlink and when the user hovers a date it should show the hyperlink. I tried CSS it didnt work, i tried coding it in the Day_Render event, that didnt work either.

This is the code:

    Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        e.Cell.Style.Add("textDecoration", "none")
    End Sub

the rendered html:
</td><td class="calendar" align="center" style="color:DarkGray;font-size:7.5pt;width:14%;textDecoration:none;"><a href="javascript:__doPostBack('Calendar1','3068')" style="color:DarkGray" title="May 26">26</a>
0
Comment
Question by:digitalZo
  • 5
  • 4
10 Comments
 
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 21784536
IF you dont want any A in table you could do this from CSS like this:

.classNameForYourCalendar a
{
display:none;
}


IF you want only to turn off this A, you could add ID parameter for this element like <a href="..." id="turnMeOff"> </a>  and then turn it off from CSS:
#turnMeOff
{
  display:none
}

You could turn it off from JS too, but I think that you dont need that :)

hope it helps
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21784629
Nope doesn't work. Nothing happens. it still gives the same output:

<td class="calendar" align="center" style="font-size:7.5pt;width:14%;textDecoration:none;"><a href="javascript:__doPostBack('Calendar1','3075')" style="color:#006699" title="June 02">2</a></td>
0
 
LVL 2

Expert Comment

by:Keale2
ID: 21785220
digitalZo,
Try this and let me know how it goes:

Add a style in the head of your page. Also, add class="day" to each applicable anchor element.


<style type="text/css">
 
td.calendar a.day
{
	text-decoration: none !important;
}
 
td.calendar a.day:hover
{
	text-decoration: underline !important;
	color: #0000FF !important;
}
 
</style>

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 21786854
If you mean that text output is not changed - this is correct behaviour. If you would like to get rid of this, you would have to change it in code somewhere hmm... could be difficult. I just provided you code from CSS that will not display it. If you want trully erase this you have two choices - changing hard coded script, or do a workover in Javascript, that after creating this element - finds correct one and remove it by using .removeChild. Second might be more easy to do, but both are difficult. If you dont know how to do this just stick with CSS and everything will be OK i think... Hope it helps
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21791304
<<Add a style in the head of your page. Also, add class="day" to each applicable anchor element.
>>

 How do I add the day class to the anchor element? The anchor element is rendered during run time.

This is the ASP.Net calendar code:

  <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#006699" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#006699" Height="159px" Width="165px" NextMonthText="" PrevMonthText="">
            <SelectedDayStyle BackColor="#76ACC8" Font-Bold="True" ForeColor="White" />
            <SelectorStyle BackColor="#006699" ForeColor="White" />
            <WeekendDayStyle BackColor="#006699" ForeColor="White" />
            <OtherMonthDayStyle ForeColor="DarkGray" />
            <NextPrevStyle Font-Size="8pt" ForeColor="White" />
            <DayHeaderStyle BackColor="#76ACC8" ForeColor="White" Height="1px" Font-Size="7.5pt" />
            <TitleStyle BackColor="#006699" BorderWidth="1px" Font-Bold="True" Font-Size="8pt"
                ForeColor="White" Height="25px" />
            <DayStyle Font-Size="7.5pt" CssClass="day" />
           
         </asp:Calendar>

wilq32:
<<<If you mean that text output is not changed - this is correct behaviour. >>>>

Sorry, I meant it's not displaying the Calendar without hyperlinks even when I added your code
0
 
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 21797628
Hmmm it might be because of javascript styling overwrites CSS styles, in that case you have two choices - do a routine in JS, or look inside ASP libary, both options are ... stupid.. i know, but what to do ?. You could do something like this:

in onload event just fire your routine in javascript, that will localise this anchor element and remove it from calendar via .removeChild, for example:

<div> some container:
<a href="blabla" id="removeME"> some anchor </a>

</div>

<script type="text/javascript">
document.getElementById('removeME').parentNode.removeChild(document.getElementById('removeME'));
</script>
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21811012
<<<<<div> some container:
<a href="blabla" id="removeME"> some anchor </a>

</div>>>>>>>

the anchor tag is generated during runtime. how do i add the ID in that case?
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21811018
personally tho, wilq32, removing the anchor tag is not the right solution i feel. if the anchor tag is removed it wont select the date and do a postback will it?
0
 
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 21828810
anchor is only a control element. You could fire its event in other way (of course if you want to). What .js you include in your html ASP.NET ?? I think that i will have to look into their libary to remove this anchor... But do you really need to remove it? maybe some other option would be good?
0
 
LVL 10

Accepted Solution

by:
digitalZo earned 0 total points
ID: 21828837
<<But do you really need to remove it? maybe some other option would be good?>>>

i dont need to remove the anchor tag. i just dont want the "underline" to come which as far as i know is removed by coding text-decoration:none. but this solution doesnt seem to be working.

as for the anchor element, it's generated during the run time. there's no javascript involved. it's the standard asp.net calendar which behaves this way.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question