Response.Write's unusual behavior (i think)

F

Farooq Khan

why does Response.Write in a method of code-beind class when called from
inpage code (i.e in <%---%>), after creating object of that class, fails
when called
while it works perfectly ok while calling the same method same way except
for creating object instead directly calling the method?
i get this when trying to do that:-

**************************************************
Response is not available in this context.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Response is not available in
this context.

Source Error:

Line 32: for (a=1; a<8; a++)
Line 33: {
Line 34: Response.Write("<H"+a.ToString()+">Heading
<H"+a.ToString()+">");
Line 35:
Line 36: }


**************************************************

i'm new to the .NET stuff and was playing around with it when came across
above......let me know if i'm doing something wrong there.
Thanks in advance.

Best Regards,
Farooq Khan
 
J

Jim Cheshire [MSFT]

Hi Farooq,

Where is this code in your application? The Reponse object is not
available in some areas.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.


--------------------
 
G

George Ter-Saakov

Why do you instantiate WebApplication7.WebForm2?
It's done by ASP.NET.


You can not simply create instance of the WebForm and expect it to work. You
must initalize it correctly which is ASP.NET job.

What are you trying to achieve?



George.



Farooq Khan said:
attached is the code file. i have cut down all the irrelevant stuff. in
.aspx file i have commented the line of code causing the trouble. let me
know what i'm doing wrong.
in short the Response.Write call is beign made from the code behind class.

Best Regards,
Farooq Khan


Jim Cheshire said:
Hi Farooq,

Where is this code in your application? The Reponse object is not
available in some areas.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.


--------------------
From: "Farooq Khan" <[email protected]>
Subject: Response.Write's unusual behavior (i think)
Date: Thu, 23 Oct 2003 21:45:30 +0500
Lines: 36
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 202.141.251.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186093
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

why does Response.Write in a method of code-beind class when called from
inpage code (i.e in <%---%>), after creating object of that class, fails
when called
while it works perfectly ok while calling the same method same way except
for creating object instead directly calling the method?
i get this when trying to do that:-

**************************************************
Response is not available in this context.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Response is not available in
this context.

Source Error:

Line 32: for (a=1; a<8; a++)
Line 33: {
Line 34: Response.Write("<H"+a.ToString()+">Heading
<H"+a.ToString()+">");
Line 35:
Line 36: }


**************************************************

i'm new to the .NET stuff and was playing around with it when came across
above......let me know if i'm doing something wrong there.
Thanks in advance.

Best Regards,
Farooq Khan
 
J

Jim Cheshire [MSFT]

Farooq,

There are a couple of issues here:

1. Don't use inline code like you did in classic ASP. You want to keep
your ASP.NET code in your code-behind.

2. Your code is failing because you are trying to call the Method() method
on a new instance of WebForm2, and that instance does not have a Response
object. You can only access the Response object for the page that is
currently executing.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Farooq Khan" <[email protected]>
References: <[email protected]>
Subject: Re: Response.Write's unusual behavior (i think)
Date: Fri, 24 Oct 2003 13:41:33 +0500
Lines: 259
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 202.141.251.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186269
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

attached is the code file. i have cut down all the irrelevant stuff. in
.aspx file i have commented the line of code causing the trouble. let me
know what i'm doing wrong.
in short the Response.Write call is beign made from the code behind class.

Best Regards,
Farooq Khan


Jim Cheshire said:
Hi Farooq,

Where is this code in your application? The Reponse object is not
available in some areas.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.


--------------------
From: "Farooq Khan" <[email protected]>
Subject: Response.Write's unusual behavior (i think)
Date: Thu, 23 Oct 2003 21:45:30 +0500
Lines: 36
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 202.141.251.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186093
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

why does Response.Write in a method of code-beind class when called from
inpage code (i.e in <%---%>), after creating object of that class, fails
when called
while it works perfectly ok while calling the same method same way except
for creating object instead directly calling the method?
i get this when trying to do that:-

**************************************************
Response is not available in this context.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Response is not available in
this context.

Source Error:

Line 32: for (a=1; a<8; a++)
Line 33: {
Line 34: Response.Write("<H"+a.ToString()+">Heading
<H"+a.ToString()+">");
Line 35:
Line 36: }


**************************************************

i'm new to the .NET stuff and was playing around with it when came across
above......let me know if i'm doing something wrong there.
Thanks in advance.

Best Regards,
Farooq Khan
 

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

Forum statistics

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

Latest Threads

Top