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
@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?
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.
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
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
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).
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.
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.
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.
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.
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 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 :)
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 :)
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
Bump, it's kinda important and high priority :)
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
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
@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?
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
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
{
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)
{
found = controlToStartFrom.FindControl(ctrlIdToFind);
)
found;
controlToStartFrom.Controls)
{
found = FindControlRecursive(innerCtrl, ctrlIdToFind);
)
found;
}
;
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).
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
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.
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?
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.
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.
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
@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 :)
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 :)
is working on a reply...