相关文章推荐
骑白马的盒饭  ·  export to csv - ...·  1 年前    · 
道上混的稀饭  ·  C# ...·  1 年前    · 
很酷的南瓜  ·  minio 存储加密-掘金·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have started learning asp.net. I went through basics and now i am started to build small application. I am using VS 2012 and created Empty Web Application Project with VB.

I can see web.config created automatically and following are the line written in it :

<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
<configuration>
    <system.web>
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5"  />
    </system.web>
</configuration>

I created Default.aspx file and wrote following lines of code :

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" %>
    HelloWorldLabel.Text = "Hello, world!";
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
    <form id="form1" runat="server">
        <asp:Label runat="server" id="HelloWorldLabel"></asp:Label>
    </form>
</body>
</html>

When I am running this application on browsers, I am getting following error that page :

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
Compiler Error Message: BC30037: Character is not valid.
Source Error:
Line 2:  
Line 3:  <%
Line 4:      HelloWorldLabel.Text = "Hello, world!";
Line 5:  %>
Line 6:  
Source File: c:\users\anjum.banaras\documents\visual studio 2012\Projects\Students\Students\Default.aspx    Line: 4 

Can any one help me on this ? I am just beginner on asp.net. Your help can save lots of my time.

Thanking you in advance !!

Not sure wny you want to have code mixed with the markup (normally it goes in the code-behind page), but I believe you need to replace the <% and %> with <script> and <script>. – Tim Jun 9, 2014 at 6:59 Do you mean that this line should be code-behind page <% HelloWorldLabel.Text = "Hello, world!"; %> – Anjum Jun 9, 2014 at 7:07

You've set the programming language of the page to VB (Visual Basic), but the line it is complaining about is written in C# syntax. Either change the line to be valid VB code:

HelloWorldLabel.Text = "Hello, world!"

(I think that removing the ; is all that's needed, but I never code VB so I'm not sure)

or change the page language to C#:

<%@ Page Language="c#" AutoEventWireup="false" CodeBehind="Default.aspx.vb" %>
                I removed ; and it works but i am still looking for better approach. I just started learning asp.net with vb
– Anjum
                Jun 9, 2014 at 7:16
                Do i need to have code-behind file every time, I mean separating markup and server side code. Please guide me !!
– Anjum
                Jun 9, 2014 at 7:18
                This question was about solving this specific problem, so if my answer solved the problem you should mark it as accepted. The Stack Overflow format is not meant to have follow-up discussions in comments - it quickly gets messy, so please post follow up as a new separate question. If you are new to ASP.NET I'd suggest reading an ASP.NET MVC tutorial - it's far better to learn that than web forms as web forms is slowly dying.
– Anders Abel
                Jun 9, 2014 at 7:21
                No, you don't need a code behind file. But it is a good idea to separate the code from the markup.
– Anders Abel
                Jun 9, 2014 at 7:21

I copied my code to another editor (notepad++) and was able to see the problematic chars. After i removed them, the code worked again.

��myClass.myArray(28) = "myFirstValue"
��myClass.myArray(29) = "myValue"
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.