SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    conditional rendering

    I'm new to asp.net

    If I put a <script></script> tag above the </body> tag in my master page, is there a way to only have that block of code render / be sent to the client IF item.aspx is loaded? And if products.aspx or default.aspx is loaded have that <script></script> block NOT render?

    Is that what conditional rendering is?

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you want to use <asp:ContentPlaceholder> in your master page. Then item.aspx will have <asp:Content> tags with content in it and products.aspx will not.

    Or if you put the content in the masterpage's ContentPlaceholder you can put an empty <asp:Content> in products.aspx which will render nothing.

  3. #3
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NAWA-mark View Post
    Sounds like you want to use <asp:ContentPlaceholder> in your master page. Then item.aspx will have <asp:Content> tags with content in it and products.aspx will not.

    Or if you put the content in the masterpage's ContentPlaceholder you can put an empty <asp:Content> in products.aspx which will render nothing.
    You can do that?!?!

    So right now my master page has one <asp:ContentPlaceholder> tag for item.aspx content, products.aspx content etc.

    So you're saying I can have 2 <asp:ContentPlaceholder> tags in the master page and if any page is loaded and does not have a corresponding <asp:Content> tag then the placeholder just won't populate?

  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tictike View Post
    So you're saying I can have 2 <asp:ContentPlaceholder> tags in the master page and if any page is loaded and does not have a corresponding <asp:Content> tag then the placeholder just won't populate?
    Anything in the master page's ContentPlaceholder is the default that will render unless a content page overrides it.

    There are two ways to look at it. If the masterpage's ContentPlaceholders are empty then yes, what you say is correct. If the ContentPlaceholders in the masterpage contains the item.aspx information then you'll have to put an empty Content tag in the products.aspx and default.aspx page to override it with nothing.

  5. #5
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NAWA-mark View Post
    Anything in the master page's ContentPlaceholder is the default that will render unless a content page overrides it.

    There are two ways to look at it. If the masterpage's ContentPlaceholders are empty then yes, what you say is correct. If the ContentPlaceholders in the masterpage contains the item.aspx information then you'll have to put an empty Content tag in the products.aspx and default.aspx page to override it with nothing.
    Perfect! Thank you.

  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)
    For scripts, one is better off using the RegisterClientScript() method of the Page class, especially if you are registering scripts from controls that might be repeated as it is capable of keeping multiple requests straight.

    That said, adding a <Content> in the header for random page use isn't half bad.

  7. #7
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    For scripts, one is better off using the RegisterClientScript() method of the Page class, especially if you are registering scripts from controls that might be repeated as it is capable of keeping multiple requests straight.

    That said, adding a <Content> in the header for random page use isn't half bad.
    It won't be repeated. The script just has to be on one page. So your saying it's ok to use the contentplaceholder technique that NAWA-mark suggested?

  8. #8
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tictike View Post
    So your saying it's ok to use the contentplaceholder technique that NAWA-mark suggested?
    Yes it is. I use that method all the time and it works great

  9. #9
    SitePoint Member kellogg9's Avatar
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NightStalker-DNS View Post
    Yes it is. I use that method all the time and it works great
    same here


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
  •