passing values to .net user controls from umbraco Options
umbracorox
Posted: Thursday, February 28, 2008 1:49:07 PM
Rank: Newbie

Joined: 2/24/2008
Posts: 6
hello, i have created a usercontrol that resides within one of my templates.

i deployed a compiled web usercontrol dll to the bin directory and the .ascx file to usercontrols directory.

the usercontrol renders but is not taking the parameters (public properties of the usercontrol).

in macro properties i have selected .net usercontrol and selected the control which i deployed - i browsed properties from the button and it read them succesfully, so I save them.

then i placed it in the template like below;

Code:

<?ASPNET_FORM>
<?UMBRACO_MACRO macroAlias="MyUmbracoArticle" AuthorUserId="xxxxxxx-7322-4197-xxxxx-3F66xxxBB" IsPublic="false" ArticleTitle="my title" PublishDate="21/02/2008 2:41:40 PM" ArticleContent="content"></?UMBRACO_MACRO>
</?ASPNET_FORM>


my usercontrol then should display the values but it doesn't
also the properties will be read from the umbraco page fields - but i was simplifying the tests.

will this be the correct way to gather the umbraco data to supply to my usercontrol

Code:

<?ASPNET_FORM>
<?UMBRACO_MACRO macroAlias="MyUmbracoArticle" AuthorUserId="<?UMBRACO_GETITEM field="userId"/>" IsPublic="<?UMBRACO_GETITEM field="isPublic"/>" ArticleTitle="<?UMBRACO_GETITEM field="articleTitle"/>" PublishDate="<?UMBRACO_GETITEM field="publishDate"/>" ArticleContent="<?UMBRACO_GETITEM field="<?UMBRACO_GETITEM field="articleContent"/>"/>"></?UMBRACO_MACRO>
</?ASPNET_FORM>


I have been following the example from http://en.wikibooks.org/wiki/Umbraco/Samples_and_Articles/Dot_Net_Controls/Using_Dot_NET_Controls_With_Umbraco

any help would be muchly appreciated. This is killing me :P
pgnz
Posted: Saturday, March 22, 2008 12:28:28 PM
Rank: Newbie

Joined: 8/6/2006
Posts: 13
Location: Auckland New Zealand
This is from the Wiki and should point you in the right direction.

If you use usercontrols, wrapped in macros, in templates, this trick could save you a lot of time.

This is achieved by using squarebrackets and a "#". Remember, that in template you can also use # for dictionary item.

Syntax: <?UMBRACO_MACRO macroAlias="myAlias" myProperty="[#propertyAlias]" />

Sample: <?UMBRACO_MACRO macroAlias="myAlias" myProperty="[#bodyText]" />

This also works with default properties like <?UMBRACO_MACRO macroAlias="myAlias" myProperty="[#pageID]" />

More:

Label="[@name]" : Request["name"]
Label="[%name]" : Session["name"]
Label="[#name]" : Page.Elements["name"]

REF: http://en.wikibooks.org/wiki/Umbraco/Samples_and_Articles/Dot_Net_Controls/Using_Page_Properties_In_UserControls
pgnz
Posted: Saturday, March 22, 2008 12:32:40 PM
Rank: Newbie

Joined: 8/6/2006
Posts: 13
Location: Auckland New Zealand
So really quickly this is what your code should look like for your macro in your template.

Code:

<?ASPNET_FORM>
<?UMBRACO_MACRO macroAlias="MyUmbracoArticle"
AuthorUserId="[#userId]"
IsPublic="[#isPublic]"
ArticleTitle="[#articleTitle]"
PublishDate="[#publishDate]"
ArticleContent="[#articleContent]"/>
</?UMBRACO_MACRO>
</?ASPNET_FORM>



:)
widescreen
Posted: Monday, April 21, 2008 1:31:30 PM

Rank: Newbie

Joined: 3/29/2008
Posts: 9
Location: NC
Is there a way to use something like [#memberid] to pass the currently logged in member id to the user control? I can't find this in any of the references.

Best regards,

Hal
neehouse
Posted: Monday, April 21, 2008 2:13:00 PM
Rank: Umbracoholic

Joined: 7/20/2006
Posts: 1,018
Location: Charleston, West Virginia, United States
no, but you can use the api and umbraco library to obtain the information.

Reference the umbraco dll in your user control, and I think the command is umbraco.library.GetCurrentMember(), which will likely returns you the xpathnodeiterator of the member. You can then read the xml node like you would a content node. > @id would be the id of the current member.

• 2007 - 2008 MVP • Charleston, WV, USA • umbracoholic since Dec. 2004 (v.2.0) •
Achieved umbracoholic status on 2008-04-25
mortenbock
Posted: Monday, April 21, 2008 9:45:49 PM

Rank: Addict

Joined: 7/19/2006
Posts: 661
Location: Århus, Denmark
You could also use this to get a member id:

Code:

int curmemberid = umbraco.cms.businesslogic.member.Member.CurrentMemberId();


Or get a member object:

Code:

umbraco.cms.businesslogic.member.Member curmember = umbraco.cms.businesslogic.member.Member.GetCurrentMember ();


Morten Bock - Level 2 certified - My danish blog with a few english posts | CodeGarden on Facebook
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.