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

Forums / Developing with Sitefinity / Using GetItemFromUrl in SimpleView

Using GetItemFromUrl in SimpleView

1 posts, 0 answered
  1. j8
    j8 avatar
    20 posts
    Registered:
    30 Oct 2007
    09 May 2013
    Link to this post
    Hi,

    I'm trying to get the current item from the url in a SimpleView control created with Thunder;

    First time I enter a page the item can't be resolved (null), if I F5 the page the item is resolved.
    I've tried using other events but no success, anybody have an idea?
    protected override void InitializeControls(GenericContainer container) {
      SetSingleItem();
      Label messageLabel = this.MessageLabel;
      if (currentProject != null) {
        messageLabel.Text = currentProject.GetValue<Lstring>("Title");
      } else {
        messageLabel.Text = "Hello, World!";
      }
    }
     
    protected void SetSingleItem() {
      var urlParameters = this.GetUrlParameters();
      if (urlParameters != null && urlParameters.Length != 0) {
        var redirectUrl = "";
        DynamicModuleManager manager = new DynamicModuleManager();
        Type projectType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Projects.Project");
        var item = manager.Provider.GetItemFromUrl(projectType, this.GetUrlParameterString(true), out redirectUrl) as DynamicContent;
        if (item != null && item.GetType() == projectType) {
          currentProject = item;
        }
      }
    }
1 posts, 0 answered