开发者

Adding C# code inline to aspx file generates VS 2008 compile error

The inline code

<% for (int i = 0; i < ThumbnailList.Items.Count; i++)
{ Response.Write("thumbnailViews[" + i.ToString() + "] = $find('" + 
ThumbnailList.Items[i].FindControl("ThumbnailView").ClientID + "');\n"); } %>

produces a bunch of compile time errors in Visual Studio 2008 - although it works fine.

But this seems to be the exact way inline code should be added, at least according to this MS help file:

http://msdn.microsoft.com/en-us/library/ms178135(VS.80).aspx

The errors are:

  • expected expression (at "<%")
  • expected ';' (at "int i")
  • expected ')' (at ThumbnailList.Items.Count;
  • expected ';' (at " i++)")

I have done a

<%@ Page Language="C#"  ...

at the top of开发者_运维知识库 the file.


I know this doesn't answer your question, but it does address the problem of using inline code in that manner.

If a client script (I assume that's what you're trying to make here) seems to require inline asp.net code, I'd suggest moving it to the code behind and start using the ClientScriptManager class.

A good place to start would be:

http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜