By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,706 Members | 2,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,706 IT Pros & Developers. It's quick & easy.

Response.Write's unusual behavior (i think)

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.
--------------------
From: "Farooq Khan" <fa*********@hotmail.com>
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: <u1**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 202.141.251.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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


Nov 17 '05 #2

P: n/a
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" <fa*********@hotmail.com> wrote in message
news:uf**************@TK2MSFTNGP11.phx.gbl...
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 [MSFT]" <ja******@online.microsoft.com> wrote in message
news:JB**************@cpmsftngxa06.phx.gbl...
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
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.
--------------------
From: "Farooq Khan" <fa*********@hotmail.com>
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: <u1**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 202.141.251.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186093X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

why does Response.Write in a method of code-beind class when called frominpage code (i.e in <%---%>), after creating object of that class, failswhen called
while it works perfectly ok while calling the same method same way exceptfor 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 thecurrent 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 inthis 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 acrossabove......let me know if i'm doing something wrong there.
Thanks in advance.

Best Regards,
Farooq Khan


Nov 17 '05 #3

P: n/a
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
ja******@online.microsoft.com

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

--------------------
From: "Farooq Khan" <fa*********@hotmail.com>
References: <u1**************@TK2MSFTNGP12.phx.gbl> <JB**************@cpmsftngxa06.phx.gbl>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: <uf**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 202.141.251.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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 [MSFT]" <ja******@online.microsoft.com> wrote in message
news:JB**************@cpmsftngxa06.phx.gbl...
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
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.
--------------------
>From: "Farooq Khan" <fa*********@hotmail.com>
>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: <u1**************@TK2MSFTNGP12.phx.gbl>
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>NNTP-Posting-Host: 202.141.251.2
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
>Xref: cpmsftngxa06.phx.gblmicrosoft.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
>
>
>



Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.