Bizarre literal.text error

Discussion in 'ASP .Net' started by Neo Geshel, Feb 25, 2007.

  1. Neo Geshel

    Neo Geshel Guest

    Just moved to C# from VB.NET, frustrated to hell and back by inability
    to get much-copied (from about 20+ different resources) literal example
    to work.

    Master Page content:

    <meta name="keywords" content="<asp:Literal ID="ltrlKeywords"
    Runat="server" />"></meta>

    Code-Behind:

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    public partial class MySiteMaster : System.Web.UI.MasterPage{
    protected void Page_Load (object sender, EventArgs e){
    ltrlKeywords.Text="This is a test";
    }
    }


    Resulting error:

    Compiler Error Message: CS0117:
    'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a
    definition for 'Text'

    Why did I use a literal instead of focusing on the <meta> itself?
    Because I am using XHTML 1.1, and I cannot have any residual ID
    attributes hanging around (a meta element does not have an ID attribute,
    and making the meta have a runat="server" causes the ID to remain in the
    element after ASP.NET is finished with it)

    This error keeps occurring, even when I do cut-and-paste examples form
    such big-name books as Wrox ASP.NET 2.0 Pro.

    This is making me tear my hair out, and I have precious little of it
    left on top. Please help!!!

    TIA
    ...Geshel
    --
    *********************************************************************
    My return e-mail address is an automatically monitored spam honeypot.
    Do not send e-mail there unless you wish to be reported as a spammer.
    Please send all e-mail to my first name at my last name dot org, with
    a subject-line of “NEWSGROUP REPLY FOR NEO GESHEL†(all uppercase).
    *********************************************************************
    Neo Geshel, Feb 25, 2007
    #1
    1. Advertising

  2. Neo Geshel wrote:
    > Just moved to C# from VB.NET, frustrated to hell and back by inability
    > to get much-copied (from about 20+ different resources) literal example
    > to work.
    >
    > Master Page content:
    >
    > <meta name="keywords" content="<asp:Literal ID="ltrlKeywords"
    > Runat="server" />"></meta>
    >
    > Code-Behind:
    >
    > using System;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Web.UI.HtmlControls;
    >
    > public partial class MySiteMaster : System.Web.UI.MasterPage{
    > protected void Page_Load (object sender, EventArgs e){
    > ltrlKeywords.Text="This is a test";
    > }
    > }
    >
    >
    > Resulting error:
    >
    > Compiler Error Message: CS0117:
    > 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a
    > definition for 'Text'
    >
    > Why did I use a literal instead of focusing on the <meta> itself?
    > Because I am using XHTML 1.1, and I cannot have any residual ID
    > attributes hanging around (a meta element does not have an ID attribute,
    > and making the meta have a runat="server" causes the ID to remain in the
    > element after ASP.NET is finished with it)
    >
    > This error keeps occurring, even when I do cut-and-paste examples form
    > such big-name books as Wrox ASP.NET 2.0 Pro.
    >
    > This is making me tear my hair out, and I have precious little of it
    > left on top. Please help!!!
    >
    > TIA
    > ...Geshel


    It seems that there is some problem with the markup code. When you use
    the Literal control from code behind, you get an error message referring
    to the use of a HtmlGenericControl. It seems as the code does not
    produde a Literal control at all.

    You can put the Literal control in placeof the entire meta tag, and put
    the html code for the meta tag into the Literal. That way you won't put
    a server control inside an html tag, which might be the reason for your
    problems.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=, Feb 26, 2007
    #2
    1. Advertising

  3. Neo Geshel

    Neo Geshel Guest

    Göran Andersson wrote:
    > Neo Geshel wrote:
    >> Just moved to C# from VB.NET, frustrated to hell and back by inability
    >> to get much-copied (from about 20+ different resources) literal
    >> example to work.
    >>
    >> Master Page content:
    >>
    >> <meta name="keywords" content="<asp:Literal ID="ltrlKeywords"
    >> Runat="server" />"></meta>
    >>
    >> Code-Behind:
    >>
    >> using System;
    >> using System.Web;
    >> using System.Web.UI;
    >> using System.Web.UI.WebControls;
    >> using System.Web.UI.HtmlControls;
    >>
    >> public partial class MySiteMaster : System.Web.UI.MasterPage{
    >> protected void Page_Load (object sender, EventArgs e){
    >> ltrlKeywords.Text="This is a test";
    >> }
    >> }
    >>
    >>
    >> Resulting error:
    >>
    >> Compiler Error Message: CS0117:
    >> 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a
    >> definition for 'Text'
    >>
    >> Why did I use a literal instead of focusing on the <meta> itself?
    >> Because I am using XHTML 1.1, and I cannot have any residual ID
    >> attributes hanging around (a meta element does not have an ID
    >> attribute, and making the meta have a runat="server" causes the ID to
    >> remain in the element after ASP.NET is finished with it)
    >>
    >> This error keeps occurring, even when I do cut-and-paste examples form
    >> such big-name books as Wrox ASP.NET 2.0 Pro.
    >>
    >> This is making me tear my hair out, and I have precious little of it
    >> left on top. Please help!!!
    >>
    >> TIA
    >> ...Geshel

    >
    > It seems that there is some problem with the markup code. When you use
    > the Literal control from code behind, you get an error message referring
    > to the use of a HtmlGenericControl. It seems as the code does not
    > produde a Literal control at all.
    >
    > You can put the Literal control in placeof the entire meta tag, and put
    > the html code for the meta tag into the Literal. That way you won't put
    > a server control inside an html tag, which might be the reason for your
    > problems.
    >


    And that is exactly what I did, and it worked well; thanks.

    However, I just want to edit the keywords of a meta tag; to drag a
    random allotment from a database and assign them to a literal control.
    In VB.NET the above code worked just peachy. I was able to dump them
    directly into the meta tag field by using a literal between the content
    quotes. Why wouldn't this work in C#? What could the difference be?

    Also, when I removed all code-behind code, the presence of the literals
    within the meta tags mutated the meta tags dramatically. The <,> symbols
    were altered to &lt;,&gt; and it appeared that the literal had “meltedâ€
    (about the best description I can give!!!) into the meta tag (and had
    given the meta tag an id, to boot). Why such bizarre behaviour????

    TIA
    ...Geshel
    --
    *********************************************************************
    My return e-mail address is an automatically monitored spam honeypot.
    Do not send e-mail there unless you wish to be reported as a spammer.
    Please send all e-mail to my first name at my last name dot org, with
    a subject-line of “NEWSGROUP REPLY FOR NEO GESHEL†(all uppercase).
    *********************************************************************
    Neo Geshel, Feb 26, 2007
    #3
  4. Neo Geshel

    Neo Geshel Guest

    Neo Geshel wrote:
    > Göran Andersson wrote:
    >> Neo Geshel wrote:
    >>> Just moved to C# from VB.NET, frustrated to hell and back by
    >>> inability to get much-copied (from about 20+ different resources)
    >>> literal example to work.
    >>>
    >>> Master Page content:
    >>>
    >>> <meta name="keywords" content="<asp:Literal ID="ltrlKeywords"
    >>> Runat="server" />"></meta>
    >>>
    >>> Code-Behind:
    >>>
    >>> using System;
    >>> using System.Web;
    >>> using System.Web.UI;
    >>> using System.Web.UI.WebControls;
    >>> using System.Web.UI.HtmlControls;
    >>>
    >>> public partial class MySiteMaster : System.Web.UI.MasterPage{
    >>> protected void Page_Load (object sender, EventArgs e){
    >>> ltrlKeywords.Text="This is a test";
    >>> }
    >>> }
    >>>
    >>>
    >>> Resulting error:
    >>>
    >>> Compiler Error Message: CS0117:
    >>> 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a
    >>> definition for 'Text'
    >>>
    >>> Why did I use a literal instead of focusing on the <meta> itself?
    >>> Because I am using XHTML 1.1, and I cannot have any residual ID
    >>> attributes hanging around (a meta element does not have an ID
    >>> attribute, and making the meta have a runat="server" causes the ID to
    >>> remain in the element after ASP.NET is finished with it)
    >>>
    >>> This error keeps occurring, even when I do cut-and-paste examples
    >>> form such big-name books as Wrox ASP.NET 2.0 Pro.
    >>>
    >>> This is making me tear my hair out, and I have precious little of it
    >>> left on top. Please help!!!
    >>>
    >>> TIA
    >>> ...Geshel

    >>
    >> It seems that there is some problem with the markup code. When you use
    >> the Literal control from code behind, you get an error message
    >> referring to the use of a HtmlGenericControl. It seems as the code
    >> does not produde a Literal control at all.
    >>
    >> You can put the Literal control in placeof the entire meta tag, and
    >> put the html code for the meta tag into the Literal. That way you
    >> won't put a server control inside an html tag, which might be the
    >> reason for your problems.
    >>

    >
    > And that is exactly what I did, and it worked well; thanks.
    >
    > However, I just want to edit the keywords of a meta tag; to drag a
    > random allotment from a database and assign them to a literal control.
    > In VB.NET the above code worked just peachy. I was able to dump them
    > directly into the meta tag field by using a literal between the content
    > quotes. Why wouldn't this work in C#? What could the difference be?
    >
    > Also, when I removed all code-behind code, the presence of the literals
    > within the meta tags mutated the meta tags dramatically. The <,> symbols
    > were altered to &lt;,&gt; and it appeared that the literal had “meltedâ€
    > (about the best description I can give!!!) into the meta tag (and had
    > given the meta tag an id, to boot). Why such bizarre behaviour????
    >
    > TIA
    > ...Geshel


    To be more specific, the <,> of the literal, not the meta tag, had been
    degraded into &lt; and &gt; entities. As such, the literal had “meltedâ€
    into the meta tag, severely mutating it.

    ...Geshel
    --
    *********************************************************************
    My return e-mail address is an automatically monitored spam honeypot.
    Do not send e-mail there unless you wish to be reported as a spammer.
    Please send all e-mail to my first name at my last name dot org, with
    a subject-line of “NEWSGROUP REPLY FOR NEO GESHEL†(all uppercase).
    *********************************************************************
    Neo Geshel, Feb 26, 2007
    #4
  5. Neo Geshel

    Tim Clark Guest

    You can't just stick server controls in the middle of attributes like
    that. You probably want to do something like:
    <meta name="keywords" content="<%=SetContent() %>" ></meta>
    ....

    protected string SetContent()
    {
    return "This is a test";
    }

    > Just moved to C# from VB.NET, frustrated to hell and back by inability
    > to get much-copied (from about 20+ different resources) literal example
    > to work.
    >
    > Master Page content:
    >
    > <meta name="keywords" content="<asp:Literal ID="ltrlKeywords"
    > Runat="server" />"></meta>
    >
    > Code-Behind:
    >
    > using System;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Web.UI.HtmlControls;
    >
    > public partial class MySiteMaster : System.Web.UI.MasterPage{
    > protected void Page_Load (object sender, EventArgs e){
    > ltrlKeywords.Text="This is a test";
    > }
    >
    > }
    >
    > Resulting error:
    >
    > Compiler Error Message: CS0117:
    > 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a
    > definition for 'Text'
    >
    > Why did I use a literal instead of focusing on the <meta> itself?
    > Because I am using XHTML 1.1, and I cannot have any residual ID
    > attributes hanging around (a meta element does not have an ID attribute,
    > and making the meta have a runat="server" causes the ID to remain in the
    > element after ASP.NET is finished with it)
    >
    > This error keeps occurring, even when I do cut-and-paste examples form
    > such big-name books as Wrox ASP.NET 2.0 Pro.
    >
    > This is making me tear my hair out, and I have precious little of it
    > left on top. Please help!!!
    >
    > TIA
    > ...Geshel
    > --
    > *********************************************************************
    > My return e-mail address is an automatically monitored spam honeypot.
    > Do not send e-mail there unless you wish to be reported as a spammer.
    > Please send all e-mail to my first name at my last name dot org, with
    > a subject-line of "NEWSGROUP REPLY FOR NEO GESHEL" (all uppercase).
    > *********************************************************************
    Tim Clark, Feb 26, 2007
    #5
    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. Replies:
    0
    Views:
    376
  2. omission9
    Replies:
    3
    Views:
    334
    Ziaran
    Feb 23, 2004
  3. Roy Smith

    Bizarre error from help()

    Roy Smith, Aug 10, 2005, in forum: Python
    Replies:
    0
    Views:
    248
    Roy Smith
    Aug 10, 2005
  4. Delaney, Timothy (Tim)

    RE: Bizarre error from help()

    Delaney, Timothy (Tim), Aug 10, 2005, in forum: Python
    Replies:
    14
    Views:
    580
    Bengt Richter
    Aug 11, 2005
  5. 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:
    362
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page