November Happy Hour will be moved to Thursday December 5th.

Using variables in a PageLink property. Need help

Vote:
 
Im trying to make use of the pagelink property on a page. What I really want to do is make the value in the PageLink be dynamic. Current, static version: Desired version: But when i use the latter version, i get this error: "Cannot convert type 'string' to 'EPiServer.Core.PageReference'" - What is the easiest and best fix for this..? TIA
#17454
Sep 15, 2005 17:50
Vote:
 
When using the databinding expression (#), double quotes will always try to convert the result to a string, so internally your code will compile to something like this: propCtrl.PageLink = (string)MyFunction(var); Using single qoutes however will not cast to string: will compile to: propCtrl.PageLink = MyFunction(var); /Steve
#18236
Sep 15, 2005 23:36
Vote:
 
Using the singlequotes returns the error: "Cannot convert type 'string' to 'EPiServer.Core.PageReference'" Which is why im unsure what is going on. I mean, the function i call will simply sends back a useful value. But somehow the property cannot interprete it. :-/
#18237
Sep 16, 2005 10:36
Vote:
 
This is the codebehind part of what I am trying to do: public PageReference DisplayRandomSlide(int ParentID) { PageReference SlideShowContent = new PageReference((int) MyPageIDIntegerValue); return SlideShowContent; } Im calling this in my aspx page like so: However it is not returning anything at all. The problem is in the PageReference part. Can anyone help or tell me a better way to make the PageLink eat my integer values..? TIA
#18238
Sep 16, 2005 14:45
Vote:
 
Your code looks ok to me, as long as you remember to DataBind the page (or more correctly, the control). Using Single quotes should not give you the cannot convert to string exception as long as you use # and not = in your assignment. Try giving the property control an id, and set the PageLink property directly from code behind. That should work. /Steve
#18239
Sep 16, 2005 16:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.