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

Forums / Developing with Sitefinity / Setting the current view from codebehind? (3.6)

Setting the current view from codebehind? (3.6)

5 posts, 0 answered
  1. Zeke
    Zeke avatar
    4 posts
    Registered:
    03 Oct 2008
    17 Feb 2009
    Link to this post
    Hi there,

    I'm currently porting a custom module that was built using 3.5 to the new framework. What is the syntax to change the current view from the codebehind? For example, previously I had a RadGrid which listed items and was handling the ItemCommand as such in my ControlPanel class:

            private void ItemsGrid_ItemCommand(object source, GridCommandEventArgs e)
            {
                if (e.CommandName == "EditItem")
                {
                    this.selectedItem= new Guid(this.container.ListingGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
                    this.Mode = DisplayMode.EditItem;
                    this.ChildControlsCreated = false;
                }
            }

    I'd then toggle the visibility of the list or the edit/insert item template based on the Mode of the ControlPanel (I used the old Contacts module as an example.)

    What is the equivalent in the 3.6 framework to tell the ControlPanel to load the ItemUpdateView over the current ItemListView?

    Thanks
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    18 Feb 2009
    Link to this post
    Hello Developer,

    You should use one of the following methods to navigate to edit mode of the item:
    NavigateHostCommand<TView>(string param)
    NavigateRootViewCommand(string param, params Type[] viewsChain)

    Here is an example with NavigateRootViewCommand:

    private void ItemsGrid_ItemCommand(object source, GridCommandEventArgs e) 
            { 
                if (e.CommandName == "EditItem"
                { 
                    string id = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString(); 
                    NavigateRootViewCommand(id, typeof(ItemsControlPanel), typeof(ItemsUpdateView)); 
                } 
            } 

    Do let us know if you need any further assistance.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Zeke
    Zeke avatar
    4 posts
    Registered:
    03 Oct 2008
    18 Feb 2009
    Link to this post
    How do we use the parameter in the EditView?

    Thanks
  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    18 Feb 2009
    Link to this post
    the parameter is passed as a query string so you could do something like

    string param = Request.Querystring["param"]

    or cast it to whatever type you need for accessing the id of the item to be edited.

    I hope this was helpful (and correct)!
  5. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    19 Feb 2009
    Link to this post
    Hi Ezekiel,

    Josh is right, you can get the parameter through the querystring. I just want to add that instead of hardcoding the key that is used for this parameter, you can use the ParameterKey property of ViewModeControl in each view. You can also override the property if the default value "param" doesn't suit you.

    Regards,
    Slavo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
5 posts, 0 answered