Reputation: 24488
I am setting a PATH for images in my web.config file. On each page, I am setting a public property like:
public string ImgPath { get { return Config.CDNImages; } }
Then in the design page I use
<img src='<%#ImgPath%>/products/<%#Eval("prodID")%>.jpg'/></a>
It works, but now I want to add this public property on the MasterPage so I can access ImgPath on every page.
I cant seem to get the <%#ImgPath%> to work when the property in on the MasterPage. I have tried <%#Master.Page.ImgPath%> .. and many other variation, but I cant seem to get it to work.
How do I get the public property within a MasterPage on a design page using in-line request/binding?
Upvotes: 0
Views: 619
Reputation: 1164
You can use the MasterType directive.
http://dotnet.dzone.com/news/back-basics-%E2%80%93-using-mastertype
Upvotes: 0
Reputation: 4296
I don't think this will work:
<%#Master.Page.ImgPath%>
or
<%#Page.Master.ImgPath%>
Because Page.Master
returns a base class, not the specific class of your master page, which means the ImgPath property won't be available without casting the Page.Master
object. That would get very tedious to do every time.
Instead of adding the property to your master page, have you considered doing something like this?
public abstract class YourPage : Page
{
public string ImgPath
{
get { return Config.CDNImages; }
}
}
Now change your pages so they inherit from YourPage
instead of Page
, and you should have access to your method on every page.
Upvotes: 1