Copied to clipboard

Flag this post as spam?

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


  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 14, 2009 @ 17:02
    Stefan Kip
    0

    Communication between page and usercontrol

    Hi people!

    I was trying to set up a modalpopupextender, which must be callable from every page.
    So I created a usercontrol for this and placed the macro in the main masterpage. I also created a .net method ShowDialog(), so I can use the following code in child pages:
    (Master as xxxxxx).ShowDialog();

    The problem is; I don't know the Class name (xxxxxxx), because it's dynamically created (I guess)?

    Second question:
    I'd like to pass .net variables to the usercontrol, like <umbraco:macro field1="<%= btnClose.ClientID %>" />. The value won't be parsed.

    So how should I accomplish something like this?
    - Getting a reference to the masterpage to be able to call some default methods
    - Passing .NET variables to macro's like a usercontrol

    Thanks in advance

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 15, 2009 @ 20:13
    Stefan Kip
    0

    Bump, it's kinda important and high priority :)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 15, 2009 @ 20:35
    Dirk De Grave
    2

    Please don't bump, it's contra productive...

     

    That said, probably no one has ever done this before in umbraco. I guess you'll need to dive in the core code...

    Share code if you do find a solution.

     

    Cheers,

    /Dirk

  • Tim 225 posts 690 karma points
    Sep 15, 2009 @ 21:20
    Tim
    1

    Hi,

    Take a look at this post http://munkimagik.wordpress.com/2009/04/08/adding-umbraco-macro-dynamically-to-user-control/

    It doesn't cover all that you're after, but it does show how to add macros to a page on the fly and thereby allows you to pass values to it.

    Tim

     

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 16, 2009 @ 17:25
    Stefan Kip
    0

    @Dirk
    Oki, won't do it again..
    It's kind of weird that no-one has needed to do something like this before, right? How would one show a dialog with a dropdownbox in it and define a selected value then? It's really not hard when working in only ASP.NET... But with Umbraco it's impossible?!

    @Tim
    Thanks for the link, but how should I get my variable in the usercontrol which creates the Macro? It's exactly the same problem, but it had a usercontrol in between the page and the macro...

    So, does anyone have a solution for something like this? It shouldn't be rocket science I would guess?

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Sep 16, 2009 @ 23:34
    Nik Wahlberg
    0

    How is the Article that Tim posted different from what you are trying to do? Please explain your situation in more details (provide a concrete example of how you would do this is "regular" ASP.NET.

    Thanks,
    Nik

  • Jameskn 64 posts 78 karma points
    Sep 17, 2009 @ 02:11
    Jameskn
    0

     

    Assume you just want to talk then between two usercontrols on a page .. Found the code on the forum site someone had posted it for a recursive find of usercontrol on the page

    http://forum.umbraco.org/yaf_postst9889_Update-another-UserControl-from-another-Usercontrol.aspx

    He is my code below putting some that anger to use . To keep the naming simple on the usercontrol I put it in another control and then named it with the id.. Seemed to work a trick

    <-- SNIP -->

     

     

     

     

     

     

     

     

     

     

    Control

     

     

    mySide = FindControlRecursive(this.Page, "sideBasket");

     

    if (mySide != null)

    {

    MiniSideBasket.

    MiniSideBasket basket = (MiniSideBasket.MiniSideBasket)mySide;

    basket.LoadShoppingBasketWithSomething(webshopperId);

    }

     

    // Taken from http://forum.umbraco.org/yaf_postst9889_Update-another-UserControl-from-another-Usercontrol.aspx

     

    public static Control FindControlRecursive(Control controlToStartFrom, string

    ctrlIdToFind)

    {

     

    Control

    found = controlToStartFrom.FindControl(ctrlIdToFind);

     

     

    if (found != null

    )

     

    return

    found;

     

    foreach (Control innerCtrl in

    controlToStartFrom.Controls)

    {

    found = FindControlRecursive(innerCtrl, ctrlIdToFind);

     

    if (found != null

    )

     

    return

    found;

    }

     

    return null

    ;

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 17, 2009 @ 13:08
    Stefan Kip
    0

    Ok, I finally figured that I can communicate with the usercontrol on a page just like in normal asp.net.
    Like clicking a button and in the event handler of that button setting some properties via code-behind in the usercontrol.

    So that's clear to me now :)
    But the question remains: is it possible to communicate with a parent masterpage from a within a different masterpage (template).

  • Jesper Hauge 298 posts 487 karma points c-trib
    Sep 17, 2009 @ 22:23
    Jesper Hauge
    0

    In Umbraco it should be entirely possible to insert script blocks in the masterpages, which again should make it possible to communicate with the parent masterpage in the same manner as you would do it in a normal asp.net masterpag.

    Regards
    .Hauge

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 17, 2009 @ 22:39
    Stefan Kip
    0

    Thanks Jesper,
    but how should I know the current page's Master 'class-name'?

    Like I posted in my startpost, I'd normally do something like:
    (Master as xxxxxx).ShowDialog();
    where 'xxxxxx' is the class-name of the masterpage. But the Umbraco masterpage classes are generated dynamically right?
    I haven't been able to find out what the class-name of my page's master is.

    Do you know how I should find this?

    Ps. I already tried to look into the property Master.GetType().FullName, this gave me something like ASP.masterpages.homepage_master, so I tried using (Master as homepage) and (Master as HomePage), but ASP.net can't find the type.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 17, 2009 @ 22:56
    Stefan Kip
    0

    Hmm, I think I already know the answer...

    I inspected the GetType() object of a 'normal' ASP.net Masterpage with code-behind...
    Then I noticed the BaseType object and this is the type of the code-behind class.
    So I think all I have to do is define Inherits property of the mastepage's Page directive and add this class to a assembly.
    Then I will have a real class, so I can call methods and use properties of this class.

    The only thing is, that I'm not sure if I can use the methods and properties defined in the mark-up C# code. But if that's the case, I can just put the code in the assembly and use it.

    What do you people think?

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 17, 2009 @ 22:58
    Stefan Kip
    0

    And another problem could be, that the assembly's context doesn't know anything of the Umbraco masterpage's controls...
    So I'm afraid I can't do anything from within the assembly's code with the controls on the masterpage, but I'll have to try that.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 18, 2009 @ 01:23
    Stefan Kip
    0

    Err I hate it that there's no edit function :-P

    I just thought about Page.FindControl() :)
    That way I can access the controls on the masterpage from code-behind, I will let you guys know if the complete solution worked.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 18, 2009 @ 16:03
    Richard Soeteman
    0

    If you just want to set some values in 1 control and read the values in another control you can use the Page.Items Dictionary

    So in UserControl 1 you set the value Page.Items.Add("someKey",SomeObject);

    in the 2nd Usercontrol you can get the object by Var SomeObject = Page.Items["someKey"];

    More info here

    Cheers,

    Richard

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 18, 2009 @ 16:32
    Stefan Kip
    0

    @Richard
    I'm sorry, that's not the problem discussed here. Maybe I haven't been able to explain the problem clear enough. Sorry for that.

    In addition to the solution I posted above about the Page.FindControl():
    A colleague of mine gave me a hint; it's better to use an interface in the assembly of the masterpage and inherit from this interface in the mark-up's page directive. That way you can just call some methods from other pages and you can leave the C# code in the mark-up of the masterpage :)

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Sep 23, 2009 @ 11:09
    Stefan Kip
    0

    Ok, I tried it and it worked!

    Just added the Inherits property of the page directive with a valid class which inherits MasterPage. Now I can resolve the Page.Master to the class and access public methods and properties.
    As long as this class has the same controls as the MasterPage in umbraco, you don't even need to use Page.FindControl() :)

    I added the usercontrol just like I would do in asp.net, now I can fill events and other stuff in the usercontrol from the masterpage :)

Please Sign in or register to post replies

Write your reply to:

Draft