Results 1 to 8 of 8

Thread: Response write unavailable

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Response write unavailable

    I got a really wierd message when I tried to add a response.write

    I added a class to my project that would handle db access

    I have the colde like this:

    Public Class DBAccess

    Public Function GetPurchaseOrderLines(parameters) As DataTable
    Try

    //perform all db here



    Return objDt
    Catch ex As Exception
    Response.Write(ex.Message)
    End Try


    End Function


    Howcome I can't use Response.Write there? It says that it isn't available in this context... Do I have to add namespace reference for this??? That is something new to me....


    kind regards
    Henrik

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    You can't use response in a class as a class isn't linked to any webpage so it has nowhere to write the response to. How about passing the ex.message back as a string to the calling procedure and then response.write form there.

  3. #3
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Or this:

    PHP Code:
    'In the external class
    Public Sub Something (param 1 as datatype, [b]objResponse as object[/b])
    '
    Code
    objResponse
    .Write(txtVariable)
    'Code
    End Sub 
    Then, you call your sub like so:

    Something(myVar, Response)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  4. #4
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    Or will this work for you?

    using System.Web;

    ....

    HttpContext.Current.Response.Write(ex.Message)

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    No because your external class is not inherited from a class that inherits your page object. (IE, it does not have a context with which to write)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  6. #6
    Fanatic Member
    Join Date
    Jul 2001
    Location
    London UK
    Posts
    671
    But as long as it is instantiated from an object with a valid context (which it presumably is) then

    System.Web.HttpContext.Current.Response.Write will be able to use that context I think.

  7. #7
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    The ultimate proof would be just to try it.

    If this code is in a secondary page (as the original poster indicated), I don't think it would work.

    Admittedtly, I have not tried your code in the past, but I have tried the response.write and that's when I had tofind another work around.

    When I get some free time here, Ill try that.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You just pass a reference to the page to your calling function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width