473,395 Members | 1,495 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.

namespace not allowed in script code declaration block?

I have a .cs file that contains the c# script of a page:
<script language="c#" runat=server src="item.cs"/>

The file item.cs contains c# code that contains a namespace:

namespace ItemPages
{
public class ShowItemToCust
{
public static void Redirect(System.Web.HttpResponse InResponse,
int InItemId, string InOnlineId,
string InLoadId)
{
StringBuilder sb = "item_ShowToCust.aspx ";
sb.Append("?OnlineId=" + InOnlineId);
sb.Append("&ItemId=" + InItemId.ToString());
sb.Append("&Referer=" + InLoadId);
InResponse.Redirect(sb.ToString());
}
}
}

I get an error with I run the page. a namespace is not permitted in a
c# script code block in an asp.net page?

thanks,
-Steve

c:\Inetpub\wwwroot\lmartin\Controls\item.cs(6,1): error CS1519: Invalid
token 'namespace' in class, struct, or interface member declaration
c:\Inetpub\wwwroot\lmartin\Controls\item.cs(7,1): error CS1519: Invalid
token

Nov 19 '05 #1
3 7302
The <script runat=server> essentially pulls this code inside of the class
definition generated by ASP.NET from the ASPX file. So it ends up being something
like this:

public class item_aspx : System.Web.UI.Page
{
// your <script runat=server> starts here
namespace ItemPages
{
// your other stuff in here
}

// the rest of the ASPX generated class
}

See how the namespace nests inside the class definition? Can't do that. What's
put in the <script runat=server> is code that auguments the ASPX generated
class definition -- so methods, fields, properties, etc.

HTH

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a .cs file that contains the c# script of a page:
<script language="c#" runat=server src="item.cs"/>
The file item.cs contains c# code that contains a namespace:

namespace ItemPages
{
public class ShowItemToCust
{
public static void Redirect(System.Web.HttpResponse
InResponse,
int InItemId, string InOnlineId,
string InLoadId)
{
StringBuilder sb = "item_ShowToCust.aspx ";
sb.Append("?OnlineId=" + InOnlineId);
sb.Append("&ItemId=" + InItemId.ToString());
sb.Append("&Referer=" + InLoadId);
InResponse.Redirect(sb.ToString());
}
}
}
I get an error with I run the page. a namespace is not permitted in a
c# script code block in an asp.net page?

thanks,
-Steve
c:\Inetpub\wwwroot\lmartin\Controls\item.cs(6,1): error CS1519:
Invalid token 'namespace' in class, struct, or interface member
declaration c:\Inetpub\wwwroot\lmartin\Controls\item.cs(7,1): error
CS1519: Invalid token


Nov 19 '05 #2

Brock Allen wrote:
The <script runat=server> essentially pulls this code inside of the class definition generated by ASP.NET from the ASPX file. So it ends up being something like this:

public class item_aspx : System.Web.UI.Page
{
// your <script runat=server> starts here
namespace ItemPages
{
// your other stuff in here
}

// the rest of the ASPX generated class
}

See how the namespace nests inside the class definition? Can't do that. What's put in the <script runat=server> is code that auguments the ASPX generated class definition -- so methods, fields, properties, etc.

HTH
as usual Brock, it helps a lot. :) I did not realize you could nest
classes in C#. I replaced namespace with static class and all is right
with the world!

-Steve

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have a .cs file that contains the c# script of a page:
<script language="c#" runat=server src="item.cs"/>
The file item.cs contains c# code that contains a namespace:

namespace ItemPages
{
public class ShowItemToCust
{
public static void Redirect(System.Web.HttpResponse
InResponse,
int InItemId, string InOnlineId,
string InLoadId)
{
StringBuilder sb = "item_ShowToCust.aspx ";
sb.Append("?OnlineId=" + InOnlineId);
sb.Append("&ItemId=" + InItemId.ToString());
sb.Append("&Referer=" + InLoadId);
InResponse.Redirect(sb.ToString());
}
}
}
I get an error with I run the page. a namespace is not permitted in a c# script code block in an asp.net page?

thanks,
-Steve
c:\Inetpub\wwwroot\lmartin\Controls\item.cs(6,1): error CS1519:
Invalid token 'namespace' in class, struct, or interface member
declaration c:\Inetpub\wwwroot\lmartin\Controls\item.cs(7,1): error
CS1519: Invalid token


Nov 19 '05 #3
> as usual Brock, it helps a lot. :) I did not realize you could nest
classes in C#. I replaced namespace with static class and all is right
with the world!


Actually you can nest classes inside one another, you just can't embed a
namespace inside of a class.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #4

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

Similar topics

6
by: Alexander Grigoriev | last post by:
I've got a problem with GNU C++ for ARM, which is used in WindRiver Tornado 2.11 environment. I tried the following construct: void foo(); namespace N {
1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
1
by: indo3 | last post by:
HELLO For the top root element of my schema file, i want to declare following attribute: <xs:attribute name="xmlns:m" type="xs:string" default="http://www.w3.org/1998/Math/MathML"/> But...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
6
by: Michael Roper | last post by:
If I've got something like: using System; namespace myCompany.myLibrary { ...class definitions here... } in a file, such that there's nothing outside of the namespace block except
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
29
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using...
11
by: Bruno de Oliveira Schneider | last post by:
Hello all, I'm rewriting a C++ framework, so that old prefixed names are replaced by namespaces. Please consider the following class: === boundingbox.h === namespace VART { class...
17
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.