Response.Write's unusual behavior (i think)

Discussion in 'ASP .Net' started by Farooq Khan, Oct 23, 2003.

  1. Farooq Khan

    Farooq Khan Guest

    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
     
    Farooq Khan, Oct 23, 2003
    #1
    1. Advertising

  2. 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


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


    --------------------
    >From: "Farooq Khan" <>
    >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: <>
    >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
    >
    >
    >
     
    Jim Cheshire [MSFT], Oct 23, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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]" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > > This post is provided as-is with no warranties and confers no rights.
    > >
    > >
    > > --------------------
    > > >From: "Farooq Khan" <>
    > > >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: <>
    > > >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
    > > >
    > > >
    > > >

    > >

    >
    >
    >
     
    George Ter-Saakov, Oct 24, 2003
    #3
  4. 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


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

    --------------------
    >From: "Farooq Khan" <>
    >References: <>

    <>
    >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: <>
    >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 [MSFT]" <> wrote in message
    >news:...
    >> 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
    >>
    >>
    >> This post is provided as-is with no warranties and confers no rights.
    >>
    >>
    >> --------------------
    >> >From: "Farooq Khan" <>
    >> >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: <>
    >> >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
    >> >
    >> >
    >> >

    >>

    >
    >
    >
     
    Jim Cheshire [MSFT], Oct 24, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marty McDonald

    SoapException - unusual behavior

    Marty McDonald, May 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    692
    Marty McDonald
    May 19, 2004
  2. =?Utf-8?B?SGVucnk=?=

    Unusual session_end behavior...

    =?Utf-8?B?SGVucnk=?=, Jan 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    383
    =?Utf-8?B?SGVucnk=?=
    Jan 12, 2005
  3. Karlo Basic

    Unusual operator behavior

    Karlo Basic, Nov 10, 2003, in forum: C++
    Replies:
    11
    Views:
    581
    Karl Heinz Buchegger
    Nov 13, 2003
  4. Replies:
    0
    Views:
    636
  5. James

    unusual scenario for auth - I think

    James, Dec 17, 2008, in forum: ASP .Net Security
    Replies:
    2
    Views:
    698
    James
    Dec 17, 2008
Loading...

Share This Page