473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Getting invalid token error but can't see why

I'm getting a compiler error on my ASP.NET page and I can't see the
cause. I have a simple C# class compiled into a DLL and placed in my
bin directory which has a public property QuestionText. When I try
and set the property the compiler throws up

Compiler Error Message: CS1519: Invalid token '=' in class, struct, or
interface member declaration

If I don't try and set the property it prints out the default value of
the property fine.

my code is below

<%@ Page Language="C#" %>
<%@ import Namespace="MyNamespace" %>
<script runat="server">
PollQuestion pollQ = new PollQuestion();
pollQ.QuestionText = "My New Question";
</script>

<html>
<head>
</head>
<body>
<%=pollQ.QuestionText %>

</body>
</html>

The C# class is

[code:1:29c46e8760]
using System;

namespace MyNamespace
{
public class PollQuestion
{
// private members
string strQuestionText;

// empty constructor
public PollQuestion ()
{

}

// public accessors
public string QuestionText
{
get { return strQuestionText;}
set { strQuestionText = value; }
}
}
}

[/code:1:29c46e8760]

I've been trying to find the problem for a while now and so far
nobodys been able to help me.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #1
3 2705
Property Type doesnot have parenthesis

Remove parenthesis from C# Class

"Twanger" <ia*@netbyte-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
I'm getting a compiler error on my ASP.NET page and I can't see the
cause. I have a simple C# class compiled into a DLL and placed in my
bin directory which has a public property QuestionText. When I try
and set the property the compiler throws up

Compiler Error Message: CS1519: Invalid token '=' in class, struct, or
interface member declaration

If I don't try and set the property it prints out the default value of
the property fine.

my code is below

<%@ Page Language="C#" %>
<%@ import Namespace="MyNamespace" %>
<script runat="server">
PollQuestion pollQ = new PollQuestion();
pollQ.QuestionText = "My New Question";
</script>

<html>
<head>
</head>
<body>
<%=pollQ.QuestionText %>

</body>
</html>

The C# class is

[code:1:29c46e8760]
using System;

namespace MyNamespace
{
public class PollQuestion
{
// private members
string strQuestionText;

// empty constructor
public PollQuestion ()
{

}

// public accessors
public string QuestionText
{
get { return strQuestionText;}
set { strQuestionText = value; }
}
}
}

[/code:1:29c46e8760]

I've been trying to find the problem for a while now and so far
nobodys been able to help me.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 18 '05 #2
Ignore the previous message

Replace <%=XXX%> with <%#XXX%>

"Twanger" <ia*@netbyte-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
I'm getting a compiler error on my ASP.NET page and I can't see the
cause. I have a simple C# class compiled into a DLL and placed in my
bin directory which has a public property QuestionText. When I try
and set the property the compiler throws up

Compiler Error Message: CS1519: Invalid token '=' in class, struct, or
interface member declaration

If I don't try and set the property it prints out the default value of
the property fine.

my code is below

<%@ Page Language="C#" %>
<%@ import Namespace="MyNamespace" %>
<script runat="server">
PollQuestion pollQ = new PollQuestion();
pollQ.QuestionText = "My New Question";
</script>

<html>
<head>
</head>
<body>
<%=pollQ.QuestionText %>

</body>
</html>

The C# class is

[code:1:29c46e8760]
using System;

namespace MyNamespace
{
public class PollQuestion
{
// private members
string strQuestionText;

// empty constructor
public PollQuestion ()
{

}

// public accessors
public string QuestionText
{
get { return strQuestionText;}
set { strQuestionText = value; }
}
}
}

[/code:1:29c46e8760]

I've been trying to find the problem for a while now and so far
nobodys been able to help me.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 18 '05 #3
Twanger wrote:
I'm getting a compiler error on my ASP.NET page and I can't see the
cause. I have a simple C# class compiled into a DLL and placed in my
bin directory which has a public property QuestionText. When I try
and set the property the compiler throws up

Compiler Error Message: CS1519: Invalid token '=' in class, struct, or
interface member declaration

If I don't try and set the property it prints out the default value of
the property fine.

my code is below

<%@ Page Language="C#" %>
<%@ import Namespace="MyNamespace" %>
<script runat="server">
PollQuestion pollQ = new PollQuestion();
pollQ.QuestionText = "My New Question";
</script>

<html>
<head>
</head>
<body>
<%=pollQ.QuestionText %>

</body>
</html>


If you click the "Show Complete Compilation Source:" link on the error
page, you can see the C# source that the .aspx page is being parsed into
- this often helps with these kinds of problems.

In your case, the problem is that your script block gets parsed into the
..aspx page's class in the declarations block. So the first line (being
a declaration) is fine, but the next line is not.

Change you script block to something like:

<script runat="server">
PollQuestion pollQ = new PollQuestion();

public void Page_Load() {
pollQ.QuestionText = "My New Question";
}
</script>

so that the second line is inside the Page_Load() method.
--
mikeb
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: evan.cooch | last post by:
Greetings. Suppose I have some function called "CheckIt" - some function to validate form data before submitting it to e CGI script. Pretend the name of the form is "TheForm". If I use the...
0
by: s.caron | last post by:
Hi, I'm trying to open an aspx page but I have this error Compiler Error Message: CS1519: Invalid token '=' in class, struct, or interface member declaration in the line : ...
0
by: Ben Holness | last post by:
Hi all, I have a system which allows users to enter a message on a (PHP) website. This message is then put into a (MySQL) Database. A perl script then picks up the message and creates an XML...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
9
by: Sebouh | last post by:
I'm very close of shooting myself in the head right now. Why in hell does free(xx) give me an error: *** glibc detected *** free(): invalid pointer: 0x08ce6158 *** // The function returns...
1
by: miamikk | last post by:
I have created XML files using BCP in SQL with FOR XML AUTO, ELEMENTS option. When I try to databind for XML file to a GridView in ASP.NET, I get an error " 'd/Commodity Description' has an...
3
by: brad | last post by:
This works: This does not (one the end, 09 is used instead of 9) File "<stdin>", line 1 area_group = {001:06, 002:04, 003:04, 006:09} SyntaxError: invalid token Why does 09 cause an...
0
by: Rod | last post by:
This is my first WCF service and it is running on my development machine (XP Pro SP2) under IIS, I am using wsHttpBinding. (I will eventually put it onto a Windows 2003 Server running under IIS on...
0
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I have WCF service and integrated with STS (WS-Federation). The Service exposes 5 endpoints Win, UNT and Federated Windows, Federated UNT and Mex endpoint. My STS Service exposes 3 endpoints...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.