Nesting Literal Control in anchor tags

Discussion in 'ASP .Net' started by Spondishy, Mar 21, 2005.

  1. Spondishy

    Spondishy Guest

    Im running the following html snippet in my page...

    <a href='<asp:Literal id="litSubRegionCode"
    runat="server"></asp:Literal>'>Test</a>

    When I flick back to designer view I get the 'Could not re-format page'
    message.

    How do I correctly nest the literal inside the anchor tag...

    Thanks.
    Spondishy, Mar 21, 2005
    #1
    1. Advertising

  2. Spondishy

    Guest

    Why are you trying to nest a literal control inside the "href"
    property?
    The HREF property is a string. If you need to set the href property
    then consider making the <a tag a server control and set the property
    via CodeBehind.
    <a href="" runat="server" id="lnkTest">Test</a>

    In your code behind there should be a variable declared as
    protected HtmlAnchor lnkTest ;
    If there is not then define it.
    then set the property programmatically by going lnkTest.HRef = "....";
    , Mar 21, 2005
    #2
    1. Advertising

  3. Spondishy

    Spondishy Guest

    I want to use the literal control, not a htmlLink. I know I can use a
    link, but I want to build a url and add my string in the middle. The
    easiest way to do this is to use the literal control.

    Anyone have an answer?

    Thanks.
    Spondishy, Mar 21, 2005
    #3
  4. Spondishy

    Guest

    A Literal control cannot be put inside of an Attribute.
    an ASPX follows basic HTMl/SGML based rules.
    <root propery="<tag></tag>" is MALFORMED SGML and therefore is not
    tolerated.

    If you wish to use an existing value such as

    <a href="/Dir/|/Action.aspx" runat="server" id="lnkTest">Test</a>

    In your code behind there should be a variable declared as
    protected HtmlAnchor lnkTest ;
    If there is not then define it.
    then set the property programmatically by going lnkTest.HRef = "....";

    or since you said you wanted to "build a url and add my string in the
    middle"
    then do something like this
    lnkTest.HRef = lnkTest.HRef.Replace("|", CurrentAction); // where
    CurrentAction is some string that you want to dynamically insert or
    maybe a variable from your web.config. etc
    , Mar 21, 2005
    #4
  5. Spondishy

    Guest

    You may also be able to go <a href="Dir/<%= somevariable
    %>/Action.aspx"></a> but having made the migration to asp.net along
    time ago I would never do something like that so I am not sure as to
    whether that is the exact syntax for asp.net or at what lifecycle stage
    you would need to ensure somevariable has been set.
    , Mar 21, 2005
    #5
  6. Spondishy

    Matt Berther Guest

    Hello Spondishy,

    Why not use <asp:Hyperlink id="myLink" runat="server">Test</asp:Hyperlink>

    and in your code-behind, do myLink.NavigateUrl = "~/Action.aspx?subregion="
    + subRegionVariable

    --
    Matt Berther
    http://www.mattberther.com

    > Im running the following html snippet in my page...
    >
    > <a href='<asp:Literal id="litSubRegionCode"
    > runat="server"></asp:Literal>'>Test</a>
    > When I flick back to designer view I get the 'Could not re-format
    > page' message.
    >
    > How do I correctly nest the literal inside the anchor tag...
    >
    > Thanks.
    >
    Matt Berther, Mar 21, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVmZlA=?=

    literal & chanracter in anchor tag name

    =?Utf-8?B?SmVmZlA=?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    508
    =?Utf-8?B?SmVmZlA=?=
    Apr 24, 2006
  2. HillBilly
    Replies:
    1
    Views:
    395
    HillBilly
    Aug 13, 2008
  3. Stephen Miller
    Replies:
    12
    Views:
    742
    Stephen Miller
    Jan 20, 2004
  4. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    363
    Anonieko Ramos
    Sep 27, 2004
  5. Trans
    Replies:
    10
    Views:
    286
    Sean O'Halpin
    Sep 16, 2005
Loading...

Share This Page