A problem with Single-File ASPXs

G

Guest

I've been using my installed VS 2005 for several months with no problem.
Suddenly, something strange is happeneing and I'm not sure if it's something
I'm missing in ASP.NET or something that's gotten messed up in VS.

If I create a completely new Web Site Project in a blank directory with
nothing in it, VS automatically creates a single Default.aspx with a
code-behind page. If I go in and edite the Code-Behind and insert something
like a Response.Write(), all goes well.

But if I try to create a new ASPX file and I uncheck the "Place code in a
separate file" checkbox, and then I try to place that same Response.Write()
in a server-side script block in the actual ASPX file, I get weird parsing
errors and t=the pop-down intellisense feature doesn't even show the Response
object as being available in scope. How is this possible? What's wrong with
my extremely simple stand-alone ASPX file?

Below is the full text of this extremely short file and would love it if
someone could tell me what could possibly be wrong with it! I've even
manually placed a bunch of <%@ Import Namespace=...%> things in there but
that doesn't seem to fix the problem!

Default.aspx...
--------------------------------------------------
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="C#" runat="server">
Response.Write("???");
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

--------------------------------------------------
 
W

Walter Wang [MSFT]

Hi,

Thanks for your posting.

In Single-File Page Model, the script block can contain as much code as the
page requires. The code can consist of event handlers for controls on the
page, methods, properties, and any other code that you would normally use
in a class file. At run time, a single-file page is treated as a class that
derives from the Page class. The page does not contain an explicit class
declaration. Instead, the compiler generates a new class that contains the
controls as members.

As in your sample code, you might need to wrap the "Response.Write ..."
code in a method.

If there is anything unclear, please feel free to post here.

Regards,

Walter Wang
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top