Bizarre literal.text error

N

Neo Geshel

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).
*********************************************************************
 
G

Guest

Neo said:
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.
 
N

Neo Geshel

Göran Andersson said:
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).
*********************************************************************
 
N

Neo Geshel

Neo said:
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).
*********************************************************************
 
T

Tim Clark

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";
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top