1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / retrieve event id from event page

retrieve event id from event page

6 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    30 Sep 2008
    Link to this post
    Is it possible to get the event id from an eventview page? I'm wanting to create a link to an asp.net event handler that needs the id passed as a parameter, but I don't know how to retrieve it from the page. can this be done?
  2. Joe
    Joe avatar
    64 posts
    Registered:
    05 Jul 2012
    30 Sep 2008
    Link to this post
    I opened up a support ticket on this a while ago.  I was trying to build a http handler that would generate an calendar invite for each event.  I was told to extend the ContentView control and generate the property or update and existing control on the page.  I have not gotten it to work yet but I have not tried that much.

    Joseph Guadagno
    Southeast Valley .NET User Group
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    30 Sep 2008
    Link to this post
    lol this is exactly what I'm trying to do. I've already completed the handler, I just need a way to pass the id into the string. I was hoping I wouldn't have to go this route as I hate to extend the contentview to just retrieve one single property that oughta be there anyway...

    sitefinity team: any chance accessing this property (ID) will be available in the 3.5 release?
  4. Joe
    Joe avatar
    64 posts
    Registered:
    05 Jul 2012
    30 Sep 2008
    Link to this post
    I completed the handler also and it works great.

    Here is what I have created or recieved from Sitefinity tech support for overriding the ContentView control.

    1#region Base overrides 
    2 
    3/// <summary> 
    4/// Overridden. Called every time a content item is being set. The method gets 
    5/// the container in which the child controls are located and <see cref="IContent"/> object 
    6/// representing the content 
    7/// </summary> 
    8/// <param name="itemContainer"></param> 
    9/// <param name="contentItem"></param> 
    10protected override void SetItemContent(Control itemContainer, IContent contentItem) 
    11
    12    base.SetItemContent(itemContainer, contentItem); 
    13 
    14    // find the link control in the container 
    15    HyperLink addToOutlook = (HyperLink)itemContainer.FindControl("addToOutlook"); 
    16     
    17    if (addToOutlook != null
    18    { 
    19        // get the ID of IEvent object 
    20        Guid eventId = FindEventId(contentItem); 
    21        // set the url of the link 
    22        addToOutlook.NavigateUrl = String.Format("~/GetICSFile.ashx?guid={0}", eventId); 
    23    } 
    24 
    25    HyperLink addToGoogle = (HyperLink)itemContainer.FindControl("addToGoogle"); 
    26    if (addToGoogle != null
    27    { 
    28        // get the ID of IEvent object 
    29        Guid eventId = FindEventId(contentItem); 
    30        // set the url of the link 
    31        addToGoogle.NavigateUrl = String.Format("~/GetICSFile.ashx?guid={0}", eventId); 
    32    } 
    33
    34
    35#endregion 
    36
    37#region Helper functions 
    38 
    39/// <summary> 
    40/// Gets the ID of <see cref="IEvent"/> object based on the <see cref="IContent"/> object associated with it. 
    41/// </summary> 
    42/// <param name="cnt">The <see cref="IContent"/> object</param> 
    43/// <returns></returns> 
    44private Guid FindEventId(IContent cnt) 
    45
    46    if (cnt == null
    47        return Guid.Empty; 
    48 
    49    EventsManager eManager = new EventsManager(cnt.ProviderName); 
    50    IEvent @event = eManager.GetEventByContentId(cnt.ID); 
    51    if (@event != null
    52        return @event.ID; 
    53     
    54    return Guid.Empty; 
    55
    56
    57#endregion 



    Joseph Guadagno
    Southeast Valley .NET User Group

  5. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    30 Sep 2008
    Link to this post
    WELL!! I managed to totally hack this together to work. what I did was drop a user control into the eventview page, then used reflection to navigate back through the eventview to get the item id. once I got that i just needed to use the event manager to grab the event by the content item id!!

    then I just find the hyperlink control I added to the same eventview page and modify it to link to the handler with the event id. TOTALLY WORKS!!

    here's the code behind for the user control:

    using System;  
    using System.Collections.Generic;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using Telerik.Events;  
    using Telerik.Events.WebControls;  
     
    public partial class UserControls_Internal_CalendarReminder : System.Web.UI.UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            EventsView view = Parent.Parent.Parent as EventsView;  
            HyperLink lnk = Parent.FindControl("CalendarReminder"as HyperLink;  
            EventsManager mgr = new EventsManager("Events");  
            IEvent ev = mgr.GetEventByContentId(view.SelectedItemId);  
            lnk.NavigateUrl = string.Format("~/EventReminder.ashx?id={0}", ev.ID);  
            lnk.Text = "Save To Outlook Calendar";  
        }  
    }  
     

    I can see potentional for all kinds of customization of the content view now that I've found a way to get in there! but are there any dangers to accessing the content this way?

    screen cap of example

    i don't have a live example to show because we're waiting for the new 3.5 sitefinity release to upload all new updates...

    hope this was helpful!
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    01 Oct 2008
    Link to this post
    Hello Josh,

    Thanks a lot for sharing your code samples. As a note of gratitude we have updated your Telerik account.

    Regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
6 posts, 0 answered