Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Jul 15, 2010 @ 12:44
    Sebastiaan Janssen
    0

    Go to specific tab after refresh

    Some custom datatypes I've made alter the content of a node after clicking the save & publish button. However, since it's an afterSave handler, once the normal reload happens, the OLD values are still shown in the backoffice.

    To make this a bit easier for the content editors, I do a response.redirect to the current URL on these datatypes. There's one little problem with that though: the active tab gets lost. Is there a way that I can maybe add tab to be activated to the url, like /umbraco/editContent.aspx?id=2625&tab=3 or something like that? Any other ideas?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 15, 2010 @ 13:00
    Aaron Powell
    0

    I think with 4.5 it's possible, I made a client API for the tab control (which just wrapped the old client side methods).

    It's not going to be an easy job, your data type needs to set a page load javascript event which finds the tab you need to navigate to and then invoke a click on it.

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Sep 09, 2010 @ 16:57
    Sebastiaan Janssen
    0

    I've seen some crazy javascript stuff from you recently, any new insites on how to go to a tab direcly? I'm no JS wizard.. 

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 11, 2010 @ 11:12
    Aaron Powell
    1

    Hah no Shan is the one who does the crazy JavaScript, mine is only insane ;).

    It's actually not really JavaScript that you need to run, the problem is the server code you need write!

    Umbraco.Controls.TabView.setActiveTab(tabViewId, tabPageId, arrayOfTabPageIds);

    Now what you need is:

    • tabViewId
    The ClientID of the TabView control, your DataType should be able to find it by walking up the control tree.
    • tabPageId
    This is the client ID of the tab that you want to show (you can get this from the TabPage control's ClientID property + "_tab0" + the position in the array of TabPages). The DataType should be able to find this without a huge problem, you'll just need to walk the control tree a bit.
    • arrayOfTabPageIds
    At least that's what I think this is, you'll have to experiment a bit. You *should* be able to work it out from the TabView control.
    Like I said, it's not going to be easy to do the code, there'll be a lot of walking the control tree to find what you need. I've based this from the code in the TabView class (umbraco.controls project) .
    I'd love to see it in action, good luck :D

  • Emmanuel Bellas 6 posts 26 karma points
    Nov 20, 2010 @ 04:35
    Emmanuel Bellas
    0
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 20, 2010 @ 22:53
    Aaron Powell
    0

    It's not in an assembly, it's a JavaScript method

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 17, 2011 @ 18:34
    Tom Fulton
    0

    Hey Sebastiaan,

    Did you ever figure this one out?  Looking to do the same and having issues finding the control ID's etc.

    Thanks,
    Tom

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Feb 18, 2011 @ 08:28
    Sebastiaan Janssen
    0

    Unfortunately, it took way too much time to get my head around this, so I couldn't. If you find a solution I would love to know about it!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 22, 2011 @ 14:51
    Tom Fulton
    2

    Did some digging and came up with the solution.

    In my case, I have a button on a datatype that performs some actions on the page's properties, then redirects back to editContent.aspx.  In order to show a speechbubble I set a Session variable (needsResync) before doing the redirect, and check for this in the Page_Load Event.  I was able to add the below code there to reset the tab:

    First, before redirecting (on the button click code), grab the active tab ID and store in a session

       TabView tv = (TabView)Page.Master.FindControl("body").FindControl("TabView1");
    HttpContext.Current.Session["activeTab"] = this.Parent.Page.Request.Form[tv.ClientID + "_activetab"];

    // Set a flag so we know to show bubble/reset tab
    HttpContext.Current.Session["needsResync"] = true;

    On the Page_Load Event after the redirect

        if (Convert.ToBoolean(HttpContext.Current.Session["needsResync"]))
        {
            // Other stuff .....

            // Reset the active tab:

            // Find the Tabview
            TabView tv = (TabView)Page.Master.FindControl("body").FindControl("TabView1");

            // Create an array of the tabs to pass into setActiveTab
            string strTmp = "";
            for (int i = 1; i <= tv.Controls.Count; i++)
            {
                if (i > 1)
                    strTmp += ",";
                strTmp += "\"" + tv.ClientID + "_tab0" + i + "\"";
            }

            string TabId = HttpContext.Current.Session["activeTab"].ToString();
     
            this.Page.ClientScript.RegisterStartupScript(
                this.GetType(),
                "resetActiveTab",
                "jQuery(document).ready(function(){var " + this.ClientID + "_tabs = new Array(" + strTmp + ");setActiveTab('" + tv.ClientID + "','" + TabId + "'," + this.ClientID + "_tabs);});",
                true);

            HttpContext.Current.Session["needsResync"] = false;
        }

    Working great!  Hope this helps someone

    -Tom

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Feb 22, 2011 @ 15:00
    Sebastiaan Janssen
    0

    Interesting approach Tom, unfortunately, I am using the default datatypes (in my case the Upload datatype for example) and I am dependent on the "Save" button in Umbraco. So the only way I can execute some code is in the AfterSave event handler, but I can't access the Page object like this in said event handler..

    Bookmarked though, this might come in handy someday, thanks!!

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Feb 22, 2011 @ 15:06
    Sebastiaan Janssen
    0

    Ooh, one hack I can think of: Make a new datatype that has some javascript that will detect clicks on tabs. Write the tab ID to a cookie and on page load, find the cookie and then set the active tab. It's a hack and requires a "dummy" datatype, but that might just be enough. I don't have time at the moment, but I will be trying this soon if nobody beats me to it.

Please Sign in or register to post replies

Write your reply to:

Draft