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?
I don’t think this will work:
Because
Page.Masterreturns a base class, not the specific class of your master page, which means the ImgPath property won’t be available without casting thePage.Masterobject. 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?
Now change your pages so they inherit from
YourPageinstead ofPage, and you should have access to your method on every page.