Simple request.querystring problem

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Jan 26, 2005.

  1. Can someone please tell me why this doesn't work!

    Error:
    Request is not available in this context

    Private rowID As Integer = Request.QueryString(ID)

    I need to have the variable rowID accessable by a number of other functions
    and subs but when I do the above I get the following error!

    However if I do

    Private rowID As Integer = "1"

    It works fine!

    Can someone please help!

    Thanks
    =?Utf-8?B?VGltOjouLg==?=, Jan 26, 2005
    #1
    1. Advertising

  2. The error is not the assigning, its that you cant access request in that
    context.
    You might get more help if you tell us where you have that line of code.

    /Dan

    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > Can someone please tell me why this doesn't work!
    >
    > Error:
    > Request is not available in this context
    >
    > Private rowID As Integer = Request.QueryString(ID)
    >
    > I need to have the variable rowID accessable by a number of other
    > functions
    > and subs but when I do the above I get the following error!
    >
    > However if I do
    >
    > Private rowID As Integer = "1"
    >
    > It works fine!
    >
    > Can someone please help!
    >
    > Thanks
    Daniel Carlsson, Jan 26, 2005
    #2
    1. Advertising

  3. Hi,

    Thanks for the reply!

    The code looks something like this!

    Thanks

    Private rowID As Integer = Request.QueryString(ID)

    Private Function GetDocument() As String
    Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
    pageID=" + rowID.ToString()))
    Dim table As DataTable = ds.Tables(0)
    Dim row As DataRow = table.Rows(0)
    Dim doc As String = row("content").ToString()
    Return doc
    End Function 'GetDocument

    Private Sub UpdateDocument(ByVal doc As String)
    Dim strSQL As String = ""
    strSQL += "UPDATE tblPageContent SET content='"
    strSQL += (doc.Replace(Chr(39), Chr(39) + Chr(39)))
    strSQL += "' WHERE pageID=" + rowID.ToString()
    RunQuery((strSQL))
    End Sub 'UpdateDocument

    "Daniel Carlsson" wrote:

    > The error is not the assigning, its that you cant access request in that
    > context.
    > You might get more help if you tell us where you have that line of code.
    >
    > /Dan
    >
    > "Tim::.." <myatix_at_hotmail.com> wrote in message
    > news:...
    > > Can someone please tell me why this doesn't work!
    > >
    > > Error:
    > > Request is not available in this context
    > >
    > > Private rowID As Integer = Request.QueryString(ID)
    > >
    > > I need to have the variable rowID accessable by a number of other
    > > functions
    > > and subs but when I do the above I get the following error!
    > >
    > > However if I do
    > >
    > > Private rowID As Integer = "1"
    > >
    > > It works fine!
    > >
    > > Can someone please help!
    > >
    > > Thanks

    >
    >
    >
    =?Utf-8?B?VGltOjouLg==?=, Jan 26, 2005
    #3
  4. Oh right, I didnt realize you had written Private (ie that it was a class
    field)
    If you set the field like you do there its called as if from the
    constructor. The constructor will be called before you get any Request (as
    far as I know). Move the rowID = Request.QueryString(ID) to Page_Load
    instead on your Page object, then you have a valid Request.

    If you ever think about doing similar to that with a string variable instead
    I strongly suggest replacing ' with \' so you dont open up security holes
    (if you had String instead of Integer I could have typed "0'; DROP TABLE
    tblPageContent;" in your textbox).

    Hope that helps
    /Dan

    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > Hi,
    >
    > Thanks for the reply!
    >
    > The code looks something like this!
    >
    > Thanks
    >
    > Private rowID As Integer = Request.QueryString(ID)
    >
    > Private Function GetDocument() As String
    > Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
    > pageID=" + rowID.ToString()))
    > Dim table As DataTable = ds.Tables(0)
    > Dim row As DataRow = table.Rows(0)
    > Dim doc As String = row("content").ToString()
    > Return doc
    > End Function 'GetDocument
    >
    > Private Sub UpdateDocument(ByVal doc As String)
    > Dim strSQL As String = ""
    > strSQL += "UPDATE tblPageContent SET content='"
    > strSQL += (doc.Replace(Chr(39), Chr(39) + Chr(39)))
    > strSQL += "' WHERE pageID=" + rowID.ToString()
    > RunQuery((strSQL))
    > End Sub 'UpdateDocument
    >
    > "Daniel Carlsson" wrote:
    >
    >> The error is not the assigning, its that you cant access request in that
    >> context.
    >> You might get more help if you tell us where you have that line of code.
    >>
    >> /Dan
    >>
    >> "Tim::.." <myatix_at_hotmail.com> wrote in message
    >> news:...
    >> > Can someone please tell me why this doesn't work!
    >> >
    >> > Error:
    >> > Request is not available in this context
    >> >
    >> > Private rowID As Integer = Request.QueryString(ID)
    >> >
    >> > I need to have the variable rowID accessable by a number of other
    >> > functions
    >> > and subs but when I do the above I get the following error!
    >> >
    >> > However if I do
    >> >
    >> > Private rowID As Integer = "1"
    >> >
    >> > It works fine!
    >> >
    >> > Can someone please help!
    >> >
    >> > Thanks

    >>
    >>
    >>
    Daniel Carlsson, Jan 26, 2005
    #4
  5. Thanks!

    "Daniel Carlsson" wrote:

    > Oh right, I didnt realize you had written Private (ie that it was a class
    > field)
    > If you set the field like you do there its called as if from the
    > constructor. The constructor will be called before you get any Request (as
    > far as I know). Move the rowID = Request.QueryString(ID) to Page_Load
    > instead on your Page object, then you have a valid Request.
    >
    > If you ever think about doing similar to that with a string variable instead
    > I strongly suggest replacing ' with \' so you dont open up security holes
    > (if you had String instead of Integer I could have typed "0'; DROP TABLE
    > tblPageContent;" in your textbox).
    >
    > Hope that helps
    > /Dan
    >
    > "Tim::.." <myatix_at_hotmail.com> wrote in message
    > news:...
    > > Hi,
    > >
    > > Thanks for the reply!
    > >
    > > The code looks something like this!
    > >
    > > Thanks
    > >
    > > Private rowID As Integer = Request.QueryString(ID)
    > >
    > > Private Function GetDocument() As String
    > > Dim ds As DataSet = GetDataSet(("SELECT * FROM tblPageContent WHERE
    > > pageID=" + rowID.ToString()))
    > > Dim table As DataTable = ds.Tables(0)
    > > Dim row As DataRow = table.Rows(0)
    > > Dim doc As String = row("content").ToString()
    > > Return doc
    > > End Function 'GetDocument
    > >
    > > Private Sub UpdateDocument(ByVal doc As String)
    > > Dim strSQL As String = ""
    > > strSQL += "UPDATE tblPageContent SET content='"
    > > strSQL += (doc.Replace(Chr(39), Chr(39) + Chr(39)))
    > > strSQL += "' WHERE pageID=" + rowID.ToString()
    > > RunQuery((strSQL))
    > > End Sub 'UpdateDocument
    > >
    > > "Daniel Carlsson" wrote:
    > >
    > >> The error is not the assigning, its that you cant access request in that
    > >> context.
    > >> You might get more help if you tell us where you have that line of code.
    > >>
    > >> /Dan
    > >>
    > >> "Tim::.." <myatix_at_hotmail.com> wrote in message
    > >> news:...
    > >> > Can someone please tell me why this doesn't work!
    > >> >
    > >> > Error:
    > >> > Request is not available in this context
    > >> >
    > >> > Private rowID As Integer = Request.QueryString(ID)
    > >> >
    > >> > I need to have the variable rowID accessable by a number of other
    > >> > functions
    > >> > and subs but when I do the above I get the following error!
    > >> >
    > >> > However if I do
    > >> >
    > >> > Private rowID As Integer = "1"
    > >> >
    > >> > It works fine!
    > >> >
    > >> > Can someone please help!
    > >> >
    > >> > Thanks
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?VGltOjouLg==?=, Jan 26, 2005
    #5
    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. Daniel Bass
    Replies:
    2
    Views:
    3,695
    dave wanta
    Jul 4, 2003
  2. George
    Replies:
    5
    Views:
    6,588
    George
    Apr 2, 2004
  3. michaaal
    Replies:
    6
    Views:
    397
    Michael D. Kersey
    Jul 15, 2003
  4. John Davis
    Replies:
    2
    Views:
    372
    Dave Anderson
    Aug 18, 2003
  5. Ivan
    Replies:
    5
    Views:
    149
Loading...

Share This Page