Calender control - how to get the day hyperlink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    Calender control - how to get the day hyperlink

    Gang, using the dayrender event I'd like to cast the hyperlink that displays the day to a linkbutton or some type of aspx control to where I can apply some custom javascript to it. For the life of me I can't figure out how to do this. Cast, CType, DirectCast don't work. The control renders itself as a <a href></a> literal control . Any tips on an approach?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Can you post the code you've tried along with any error messages?

    Comment

    • yarbrough40
      Contributor
      • Jun 2009
      • 320

      #3
      I'm not at my machine now but a code example is something like
      Code:
      DIm lb as LinkButton = CType(e.cell.Controls(0),LinkButton)
      the error is 'cannot cast type LiteralControl to type LinkButton...'

      Anyway, as a solution, I decided to simply clear the controls in the cells, then dynamically create my own linkbuttons. I would prefer to avoid this if I could only because it creates a little more overhead on the postback.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Place a break point on that line and find out which index the LinkButton control exists?



        -Frinny

        Comment

        • yarbrough40
          Contributor
          • Jun 2009
          • 320

          #5
          Thanks, the control exists at index 0. the problem is that there is no way to cast the control to some type of aspx type in order to apply custom attributes to it.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Oh, I see what you are trying to do.
            Hmm...you can't do that.

            When it is rendered, does the day have an ID associated with it?

            -Frinny

            Comment

            • yarbrough40
              Contributor
              • Jun 2009
              • 320

              #7
              yes, e.day.date is there so the solution I have settled on is to just clear out the controls in each day cell then instantiate a new linkbutton using that date. It would be nice to avoid that route simply to keep the overhead down. asp.net as we know is pretty resource heavy in general. It is what it is : )

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                You might have to overwrite the controls...

                Or you could look into a JavaScript solution that attaches a click event to the "day" since there is an HTML element with an ID for the "day". Unless you meant to say "no, there is no ID associated with the Day".

                -Frinny

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  It really sounds like you are doing something more than you probably need to. What exactly are you trying to accomplish?

                  -Frinny

                  Comment

                  • yarbrough40
                    Contributor
                    • Jun 2009
                    • 320

                    #10
                    I want to add custom javascript to the existing day hyperlink so that onmouseover I can identify that it is truly a click on that hyperlink as opposed to a click on the larger day-cell (I am firing a different event on the cell click).

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Ok, write a JavaScript function that retrieves all of the hyperlinks within your calendar.

                      I believe the calendar is rendered as a table right?
                      The table should have an ID and you can use the document.getEle mentByID() method to retrieve it. Once you have the table, you can use tableVariable.g etElementsByTag Name() to retrieve all of the hyperlinks within the table.

                      You can then loop through the hyperlinks and attach a click event to them so that you can set a hidden variable or something in order to indicate that it was the hyperlink clicked, as opposed to the cell.

                      -Frinny

                      Comment

                      • yarbrough40
                        Contributor
                        • Jun 2009
                        • 320

                        #12
                        use a JS loop... great idea!

                        Comment

                        Working...