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
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.