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