Attribute "runat" is not a valid attribute. Did you mean "content" or "target"? How to solve this asp.net validation error - asp.net

see here this error - http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fwww.sitecore.net%2F

runat="server" is asp.net server control syntax. It must not come in html. It is interpreted by ASP.NET. you must remove this attribute.
Possible Reason for this:
1. I think the template is dynamically created. the developer make static site and cut copy paste on server side to make it dynamic but use control as response.write and forgot to remove runat="server" because it must be html content in response.write.
NOTE: No ASP.NET server control gives runat="server" in HTML. It is hardcoded in your code. remove this from both anchor and image tag.

Er... remove the attributes? They aren't valid HTML, and they're only meaningful when interpreted by ASP.NET.

Your pages should not be rendered with runat="server", so something's definitely going wrong here. What does the part of your aspx look like, that corresponds to one of the elements that is giving this validation error?

Related

How to prevent asp.net to make lowercase my custom attribute I placed in a server control

I have an aspx page and controls on it. For the purpose consuming it at client side javascript I would like to place attributes for my elements. I would like to do it all in the markup, not in code behind. It seems the placed attributes will be all lowercased at client side.
For example:
<asp:LinkButton ID="anyButton" runat="server" confirmationMessage='any message'...
will be rendered at client side as:
<a confirmationmessage='any message'...
Consequently I must use this casing all my javascript code. Not a big issue, but quite disturbing if you like strict naming conventions.
Thanks in advance

X is missing a required attribute 'runat', but runat has one option only

I wonder, why do I have to include runat="server" to server elements in ASP.NET when runat only has one option and it is required for server elements. If not added it keeps telling me "missing a required attribute 'runat'".
Am I missing something here?
The runat="server" is there to let ASP.NET know which parts of your HTML is controlled server-side and which parts are not.
Please note that even standard HTML elements like <table> can have a runat="server", which then exposes it to your code.
Here is a previous StackOverflow question that has input from some people at Microsoft as to why the runat="server" tag is explicitly necessary for server tags, while causing errors if omitted.
Why does ASP.NET webforms need the Runat=“Server” attribute?

ASP.NET inline code in a server control

Ok, we had a problem come up today at work. It is a strange one that I never would have even thought to try.
<form id="form1" runat="server" method="post" action="Default.aspx?id=<%= ID %>" >
Ok, it is very ugly and I wouldn't have ever tried it myself. It came up in some code that was written years ago but had been working up until this weekend after a bunch of updates were installed on a client's web server where the code is hosted.
The actual result of this is the following html:
<form name="form1" method="post" action="Default.aspx?id=<%= ID %>" id="form1">
The url ends up like this:
http://localhost:6735/Default.aspx?id=<%= ID %>
Which as you can see, demonstrates that the "<" symbol is being encoded before ASP.NET actually processes the page. It seems strange to me as I thought that even though it is not pretty by any means, it should work. I'm confused.
To make matters worse, the client insists that it is a bug in IE since it appears to work in Firefox. In fact, it is broken in Firefox as well, except for some reason Firefox treats it as a 0.
Any ideas on why this happens and how to fix it easily? Everything I try to render within the server control ends up getting escaped.
Edit
Ok, I found a "fix"
<form id="form1" runat="server" method="post" action='<%# String.Format("Default.aspx?id={0}", 5) %>' >
But that requires me to call DataBind which is adding more of a hack to the original hack. Guess if nobody thinks of anything else I'll have to go with that.
ASP.NET 3.5 added the "Action" property to the HtmlForm control. Your previous code worked just fine because "action" was just a string, and the code nugget would emit the additional data for you. Now that there is an Action property, you can't use a simple code emit nugget, since a server-side control expects a property to have a literal string value (same as any other server-side control property).
Your workaround of using the biding syntax is correct. To make it work like it used to, you would have to remove the runat=server tag on your form, which would then prevent the ASPX parser from treating it as an HtmlForm control, and instead treat it as a literal (where your code emit nugget would be allowed to work).
Your other option, which may be much cleaner - is to simply set the Form's action property through code-behind in the page_load. The reason the action property is set the way it is, was because in earlier versions of .NET Framework, there was no support for setting the Action property.
your form needs a runat=server

Can I place a comment inside a tag in ASP.NET?

I am looking to display this in my .aspx page, without using special character XML tags, can this be achieved?
<asp:ServerTag Property1="a"
Property2="b"
Property3="c" <%-- Comment why this particular property is necessary --%>
Property4="d" />
However, I am greeted with the error message Server tags cannot contain <% ... %> constructs. If I use an HTML <!-- --> tag, I'm told the server tag is not well formed.
Is there any other syntax to make this possible?
Put server-side comment above your server-side control.
<!-- client-side comment (html) - appears in html source but not rendered on page
<%-- server-side comment - stripped out on server, never sees light of day, browser never knows about it
like this
<%-- Usage:
Property2 is xyz...
Property3 will .. abc. Ignore Property 1 when this is set. etc
--%>
<asp:ServerTag Property1="a"
Property2="b"
Property3="c"
Property4="d" />
It's just like putting source code comments above your functions.
Think "server to server". It will make the difference between your HTML source looking like
cluttered with "pass through" html comment <!--:
<!-- Property usage: abc, def, ...xyz -->
Rendered server control contents.
vs. the cleaner stripped out " <%-- source:
Rendered server control contents.
Less bandwidth with latter too. No extraneous (and confusing to user) comments in HTML source.
It's not possible, no. The server tags need to be well-formed XML and you can't have tags like that in XML. You can put a comment at the top, of course, like so:
<!-- Property2 needed because... -->
<asp:ServerTag Property1="a" Property2="b" Property3="c" />
Not necessarily like that but you may want to consider decorating the property in c# to let the user know its relevance. After that something like resharper (or maybe vs) will give you this information when you try to set it.

RegisterClientScriptBlock without form tag

After trying to understand why client code is not rendered in a page (injected by user control) I found this link, it turns out you must have a form tag for it to work (Page.RegisterClientScriptBlock did declare this but ClientScriptManager.RegisterClientScriptBlock which I use does not say anything regarding this).
I am using Visual studio 2005.
Does anyone know if this has been solved?
Edit:
To clarify, I want my control to add javascript code to the head section of the page without having to use the
<form runat="server"
I have tried adding it using:
HtmlGenericControl x = new HtmlGenericControl("script");
x.InnerText = "alert('123');";
Page.Header.Controls.Add(x);
But this did not work for me.
As far as I know this functions the same in current versions, you can test it very simply though.
Update
per discussion in the comments, the only "workaround" that I could think of would be for your to manually insert the script into the "head" section of the page on your own, using a runat="server" declaration on the Head element.
Got it!
My mistake was not doing it in the OnPreRender method (I used the Render method).
Now all that is needed is - like Mitchel Sellers wrote, set the header to runat server and than add to it's controls:
HtmlGenericControl x = new HtmlGenericControl("script");
x.InnerText = GetScriptSection();
Page.Header.Controls.Add(x);
Thanks for pointing me to the right direction!
The MSDN Page for registerclientscriptblock here says:
The client-side script is emitted just
after the opening tag of the Page
object's <form runat= server> element.
The script block is emitted as the
object that renders the output is
defined, so you must include both tags
of the <script> element.
If you do not want to include a form, than you will basically need to build your own implementation of it.
Minor clarification for anyone seeing this:
The form tag must have the runat="server" attribute set, e.g.
<form id="theform" runat="server">
Just placing a regular HTML form tag in the page will not help.

Resources