469,889 Members | 1,258 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Bizarre literal.text error

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 <metaitself?
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).
************************************************** *******************
Feb 25 '07 #1
4 2180
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 <metaitself?
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
Feb 26 '07 #2
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 <metaitself?
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).
************************************************** *******************
Feb 26 '07 #3
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 <metaitself?
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).
************************************************** *******************
Feb 26 '07 #4
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 <metaitself?
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).
************************************************** *******************

Feb 26 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.