Error in ASP.net : BC30037: Character is not valid - asp.net

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>
<body>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" id="HelloWorldLabel"></asp:Label>
</div>
</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 !!

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 was getting this error since my designer file was missing from the solution (I don't know how,seriously). So try adding a designer file for the aspx file in the solution; it worked for me.

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"

Related

ASPX Server side comments messing up controls collection

I am having one of the weirdEST issue I have ever faced. Its ridiculous.
Server side comments gets added as a LiteralControl to the original container control. I know it sounds really crazy, but thats what I am experiencing here :(
My environment: Visual studio 2012, IIS 7, .net frameworks 4.0
I am copying my test page here:
Default.aspx page:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div runat="server" id="divTest">
<%--test--%>
<%--test--%>
</div>
</form>
</body>
</html>
Default.aspx.cs:
using System;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(string.Format("divTest Control count: {0}", divTest.Controls.Count));
}
}
web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
The resulting page shows the output:
divTest Control count: 3
The funniest part is that, I tried to run this same page in 3 other boxes,( with exactly same config/environment) and it worked as expected in 2 of them and the other one showed the same result as mine. Again, if I change the build target framework version to 2.0, it shows the expected results (divTest Control count: 1). This happens only when I build it in 4.0
Any idea what could be the reason for this odd behaviour? Am i missing something here?
Thanks
Benjamin
The extra LiteralControl is not from comment but white spaces that surrounds it.
Same thing happend to me when switched from VS.NET 2010 to 2013 (yes, just upgraded VS.NET - no change in website target framework - 4.0)
The solution in my case was to use FindControl() method instead of accessing ControlCollection directly by index.

Run code in CSS file in ASP.net

In my CSS file I would like to have definitions such as:
.hr {
background:url('<%=CommonFunctions.AllocateStaticPath("/images/hr.png") %>');
width: 100%;
height: 2px;
margin: 40px 0;
}
This would be useful to me, as the path to each image differs on the production server and the development server and the function correctly sets the resources path. Being able to do this would simplify my publishing process.
How can I enable IIS7 to run ASP.net on CSS files? I've tried renaming the CSS file to .ashx and creating a rewrite rule but this seems to always 404.
This question inspired me to do some testing to see if I could somehow get the asked for syntax to work.
It turned out to be relatively easy. After a few different test versions, this is what I ended up doing.
Configuration
Create a brand new web application to test in
Create a folder called DynCss where the css files that need dynamic processing will be put
Register .css files to be handled by the Page handler for requests to this folder. For this I added the following to web.config:
<configuration>
<system.web>
...
<httpHandlers>
<add type="System.Web.UI.PageHandlerFactory" path="/DynCss/*.css" verb="GET"/>
</httpHandlers>
...
</system.web>
</configuration>
Register a build handler for .css files:
<configuration>
<system.web>
...
<compilation debug="true" targetFramework="4.0">
<buildProviders>
<add extension=".css" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
...
</system.web>
</configuration>
After doing these changes, I can proceed to testing it.
Testing
For the purpose of testing I added DynamicStyles.css to the DynCss folder. Contents of DynamicStyles.css:
<%# Page Title="DynamicStyles.css" Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType="text/css";
Response.Cache.SetCacheability(HttpCacheability.Public);
}
</script>
body {
font-weight: <%= TestDynamicCss.Code.Constants.FontWeight %>;
}
Note: The TestDynamicCss.Code.Constants.FontWeight referrs to a static property on a static class. I simply returns the string "bold".
Finally, I link to it in Default.aspx:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="TestDynamicCss._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="/DynCss/DynamicStyles.css" rel="Stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET! Is this now bold? Why yes, it is!
</h2>
</asp:Content>
Comments
Using this approach you get the behaviour that you asked for. The drawbacks are that you don't get any automatic cache handling as you do for static css files. Also, this approach (as far as I can tell) makes it impossible to use the Css bundling features of Asp.Net 4.5. Also (needless to say) you don't get C# intellisense when coding in the Css file.
Try this:
background:url('<%= CommonFunctions.AllocateStaticPath("/images/hr.png") %>');
Can't you just create an ASPX page that returns CSS instead of HTML? Then reference the .aspx file in your CSS declaration.
I think you can use the ashx handler a page and add the response header:
Content-Type: text/css

DevExpress CSS "dx:"

I am a new to CSS world, so please help me out to figure it out.
I have tried to use a sample css from DevExpress ASP MVC demo and I have received a below error msg. I have two questions regarding this error msg.
What do I need add to resolve this error?
What deos "dx:" means?
By the way, I am getting "Unrecognized tag prefix or device filter 'dx' in visual studio 2010.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'dx:Head'.
Source Error:
Line 14: <title></title>
Line 15: <asp:ContentPlaceHolder id="CustomTopHeadHolder" runat="server" />
Line 16: <dx:Head ID="Head" runat="server" />
Line 17: <asp:ContentPlaceHolder id="CustomHeadHolder" runat="server" />
The "dx" is just a tag to tell it is a DevExpress Command. For the error message try registering the tags you are going to use.
For example if you are planning to use a ASPxNavBar then you will have to add this
<%# Register Assembly="DevExpress.Web.v10.2, Version=10.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxNavBar" TagPrefix="dx" %>
Note this is for the Version 10.2.6. You will have to add the appropriate one for your project
Hope this helps.
Looks like a namespace prefix. Have a look at this question for guidance.

Unknown Server tag ASP.NET 2.0 Visual Studio 2010

I am in the process of upgrading a website from Visual Studio 2005 to 2010. I ran it through the importer, however I'm having some errors. Specifically I'm having the following error:
Error 615 Unknown server tag 'CTL:PayPal'
If I go to the file that it is complaining about I have the following at the top of the file:
<%# Control Language="C#" AutoEventWireup="true" Inherits="PowerShop.Admin.UI.Customer.Controls.CustomerPaymentList" %>
<%# Register TagPrefix="CTL" TagName="OrderPaymentList" Src="~/Order/Controls/OrderPaymentList.ascx" %>
<%# Register TagPrefix="CTL" TagName="PayPal" Src="~/Order/Controls/OrderWizard/PayPalDetail.ascx" %>
<%# Register TagPrefix="CTL" TagName="Term" Src="~/Order/Controls/OrderWizard/LineOfCreditDetail.ascx" %>
<%# Register TagPrefix="Shipping" TagName="AddressVerification" Src="~/Controls/AddressVerificaton.ascx" %>
<%# Import Namespace="PowerShop.Configuration" %>
I have checked and double checked the register tags and the file but everythin appears to be correct. The file exists (PayPalDetail.ascx) in the exact location I am specifying. This page does not throw any errors on any of the other register tags. Any help or insight would be much appreciated.
I think it would be in wrong place like you could have by mistake put it in the page instead of putting it in the UserControl which have the Register tag.
Also, this can occur if the Paypal user control is not able to compile due to some bug in it.
Where are you placing the CTL:Paypal tag ??
.
PS: More detailed question could have a chance of more detailed answer !

Master page gives error

I am using VS2008 for ASP.NET apps.
My Solution Explorer has hierarchy like this:
The start-up page, Default.aspx, displays a Login form. When I press Login button, another Page with the name, selectCompany, should open. selectCompany is a Web Content Form whose master page is Master1.Master. But it is not opening, instead I am getting this error:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'FlexStock.Forms.master1'.
Source Error:
Line 1: <%# Master Language="C#" AutoEventWireup="true" CodeBehind="~/Forms/selectCompany.aspx" Inherits="FlexStock.Forms.master1" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Source File: /Forms/master1.Master Line: 1
The first line of Master1.master is like this:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="master1.master.cs" Inherits="FlexStock.Forms.master1" %>
And the first line of Web Content Form, selectCompany.aspx, is like this:
<%# Page Title="" Language="C#" MasterPageFile="~/Forms/master1.Master" AutoEventWireup="true" CodeBehind="selectCompany.aspx.cs" Inherits="FlexStock.Forms.selectCompany" %>
I am not following where is the problem.
Make sure that the class-name stated in the Inhertis-part of your page-directive matches the name of the class in your code-behind file.
Master1.master:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="master1.master.cs" Inherits="FlexStock.Forms.master1" %>
Master1.Master.cs:
namespace FlexStock.Forms {
public class master1 {
/* ... */
Have you built your project w/o any errors/warning?
Error says that its unable to find code-behind class FlexStock.Forms.master1 so issue will be likely in master1.Master.cs or designer.cs - where you may have changed the namespace or class name w/o making the same change in markup. Or there is some compilation error and VS is unable to generate the assembly (or unable to put it in bin folder)
If you can see the bin folder in Explorer, but not in VS, try "Including" it in your project.
Maybe drag the folder into Solution Explorer, and then right-click it and Include it.

Resources