Hi, this is really weird!
But look at the following asp code:
<div runat="server" id="MainDiv"> <%foreach (string str in new string[]{"First#", "Second#"}) { %> <div id="<%=str.Replace("#","div") %>"> </div> <%} %> </div>
Now, if you put this code on any web page (and donβt worry about the morality of this code, I did it just to show this idea) you will get this error:
Compiler Error Message: CS1518: expected class, delegate, enumeration, interface or structure
Of course, the error has nothing to do with the real problem, I looked for the code generated by asp.net and found out the following:
private void @__RenderMainDiv(System.Web.UI.HtmlTextWriter @__w, System.Web.UI.Control parameterContainer) { @__w.Write("\r\n "); #line 20 "blabla\blabla\Default.aspx" foreach (string str in new string[] { "First#", "Second#" }) { #line default #line hidden @__w.Write("\r\n <div id=\""); #line 22 "blabla\blabla\Default.aspx" @__w.Write(str.Replace("#", "div")); #line default #line hidden @__w.Write("\">\r\n "); }
This is the code that was generated on the asp page, and this is the method that is intended to render our div (MainDiv), I found that there is no bracket "}" that closes the method or (for the loop).
Now the problem consists of three parts:
1- first you should have server control (in our situation, MainDiv), and I'm not sure if this is just a div tag.
2- HTML control inside the server control and the code inside it using the double quote mark (for example, <div id="<%=str
instead of <div id='<%=str
.
3-Any keyword that has block brackets, for example: for {}, and {}, using {} ... etc.
Now removes any part, solves the problem !!!
How does this happen? any ideas?
By the way: please help me make the question more obvious, because I could not find the best words to describe the problem.
It seems my question is incomprehensible! My question is: what are the steps that asp.net should use to generate such incorrect code? How does this happen!! I do not want a solution for the exception, I already decided to use a single quote.