1

I'am using a TBB for Ugc and when i use this code <%myTest = "<ugc:ContextVariable runat='server' Var='ugcComment.User.Name'/>";%> i don't get the value of

ugcComment.User.Name

I get ugc:ContextVariable runat='server' Var='ugcComment.User.Name'/> it don't transform it to the value of ugcComment.User.Name

Can you help me?

  • I don't understand what you are trying to do. You appear to be setting the variable "myTest" to a string that resembles a server control, when what you probably want to do is just have that server control rendered. What was your goal, exactly? – Peter Kjaer Jun 19 '14 at 11:36
  • I want to pass ugc:ContextVariable to userControl and not to display it. This is my code <%myTest.Val = "<ugc:ContextVariable runat='server' Var='ugcComment.User.Name'/>";%> <uc:ShowTest runat="server" id="myTest" /> – user1032 Jun 19 '14 at 12:11
1

From your response to my questions in the comments, it seems that you're hoping that ASP.NET will first render ugc:ContextVariable and then update myTest.Val with the result?

If so, I'm afraid it doesn't work that way. The user control will not be rendered when you put it as a string variable (how would it know that it isn't just a random string?).

It needs to be in the markup itself -- and it will then be rendered as a result of being in the Page's Controls collection. That rendering will happen to an HtmlTextWriter -- not a variable in memory.

If you want to move the rendering of the user name to a User Control of your own, simply put the ugc:ContextVariable in the ASCX for that control. It will then be rendered automatically.

If you instead must have programmatic access to the username, I'm afraid the ContextVariable control isn't the right tool for the job. But the good news is that you can call the EvaluateVariable method of the When control instead (which is what ContextVariable is doing):

var username = Tridion.ContentDelivery.UGC.Web.UI.When.EvaluateVariable("ugcComment.User.Name", HttpContext.Current);

Don't forget to check for null :)

If you'd like to know more about how ASP.NET works when it comes to rendering, I recommend reading up on the Page Life Cycle.

  • Thank you Peter that's what i search using EvaluateVariable method – user1032 Jun 19 '14 at 13:19
0

Can you ensure following:

  • Your Template's Output format is set to ASCX Control if you are intended to publish this presentation as a ASCX Control
  • Your publishing target to which you are publishing have the target language set to ASP.NET
  • For the output format i use a HTML Fragment but modifying it to ASCX Control didn't change any think – user1032 Jun 19 '14 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.