Simple request.querystring problem

G

Guest

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
 
D

Daniel Carlsson

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
 
G

Guest

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
 
D

Daniel Carlsson

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
 
G

Guest

Thanks!

Daniel Carlsson said:
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
 

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,902
Latest member
Elena68X5

Latest Threads

Top