SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ResolveUrl() w/ Master Pages

    This code doesn't seem to work for me on my Master Pages:

    Code:
    <link rel="Shortcut Icon" type="image/x-icon" href="<%# ResolveUrl("~/Favicon.ico") %>" />
    It doesn't throw an error the output source code just looks like this:

    Code:
    <link rel="Shortcut Icon" type="image/x-icon" href="" />
    If I try and use this code:

    Code:
    <%= ResolveUrl("~/Favicon.ico") %>
    This error gets thrown:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    How do I fix this? Let me know what everyone thinks, thanks.

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Are you calling DataBind on the MasterPage?

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I'm just trying to get the MasterPage.master to be global and work no matter how many pages down a page is on my site.

    Maybe I don't understand what you mean. I have a repeater control I'm using with my web.sitemap file and i'm using the <%# Eval("Url") %> statements.

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you mean that I should be calling DataBind to have this work?

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hate to post for the third time in a row but I still haven't received a straight answer on how to accomplish using the ResolveUrl() method in Master Pages to call files globally. Thanks and please help!!!

  6. #6
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Anything with databinding syntax (<%# . . . %>) needs to be databound at some point, that should fix you good.

  7. #7
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll have to forgive me here but I'm not sure what a lot of ASP.Net means right now. All I'm trying to do is find a way to include a shortcut icon and other includes in my Master Page where it will work no matter how deep the page is in the site. And I was hoping to use the ResolveUrl() method for that but it doesn't seem to be working for me.

    So what should I databind here? Or maybe there is a better approach to what I'm trying to accomplish altogether.

  8. #8
    SitePoint Zealot yacka's Avatar
    Join Date
    Aug 2006
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To clarify: At some point in your page control lifecycle you need to call the DataBind method in order for all the stuff in <%# %> blocks to be processed. So at a suitable point, say in the Load or PreRender events, add a call to this.DataBind() and it should work.

  9. #9
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, this did work, thank you. However is there any way to accomplish this without doing the databind? I get the feeling I'm "hacking" the databind instead of doing this in a legitimate way. But then again, if it works ...

  10. #10
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Actually, this is the best way to handle something like this. A slightly more common approach would be to use a literal or a html generic control and bind the data in the codebehind. But databinding like this has some significant advantages. Biggest one being this can be canged without a recompile. Want to have MM/DD/YY in there? Easy, just change the databound expression to:

    <%# DateTime.Now.ToShortDateString() %>

    Etc, etc.

  11. #11
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice, for once I thought to do something the right way the first time, just needed your help to do it! thanks again


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •