Boolean always false????

G

Guest

Can someone tell me why the value of my Boolean is always false!
Even after I have declared that my variable iNews should equal TRUE it seems
to remain false...

Can some please explain why...

Thanks

Dim iNews As Boolean
Private Function GetDocument() As String
Dim ds As DataSet

If Request.ServerVariables("HTTP_REFERER") =
"http://localhost/cpncms_v1/cms/viewpage.aspx" Then
ds = GetDataSet(("SELECT content FROM tblPageContent WHERE
pageID=" + rowID.ToString()))
iNews = True
ElseIf Request.ServerVariables("HTTP_REFERER") =
"http://localhost/cpncms_v1/cms/news/pgeEditor.aspx" Then
ds = GetDataSet(("SELECT content FROM tblNewsArchive WHERE
newsID=" + rowID.ToString()))
iNews = False
End If
Dim table As DataTable = ds.Tables(0)
Dim row As DataRow = table.Rows(0)
Dim doc As String = row("content").ToString()
Return doc
ds.Dispose()
End Function 'GetDocument

Private Sub UpdateDocument(ByVal doc As String)
Dim strSQL As String = ""
If iNews = True Then
strSQL += "UPDATE tblPageContent SET content='"
strSQL += (doc.Replace(Chr(39), Chr(39) + Chr(39)))
strSQL += "' WHERE pageID=" + rowID.ToString()
RunQuery((strSQL))
Else
strSQL += "UPDATE tblNewsArchive SET content='"
strSQL += (doc.Replace(Chr(39), Chr(39) + Chr(39)))
strSQL += "' WHERE newsID=" + rowID.ToString()
RunQuery((strSQL))
End If
iNews = Nothing
End Sub 'UpdateDocument
 
C

Clint Hill

Can you show how you are using these methods and at what point in the
page life cycle? From the code you provided, the only thing I can
imagine happening (that would keep iNews false) is that your refferer is
always showing something other than viewpage.aspx. Declaring iNews as
a boolean will default to false unless set otherwise, so if you never
touch it again, it will always be false. And your "if" condition has an
else if with no else so you don't have options other than viewpage.aspx
or pgeEditor.aspx.

One way to tell is to put a breakpoint here:

If Request.ServerVariables("HTTP_REFERER") =
"http://localhost/cpncms_v1/cms/viewpage.aspx" Then

and see the value of HTTP_REFERRER during runtime.


More code could help here, to get an idea of how your using these methods.

Clint Hill MCAD
H3O Software
http://www.h3osoftware.com
 
K

Karl Seguin

I agree....my guess is that HttpReferer is either not the expected value or
null. In which case iNews will be set to the default value of false.

Just wanted to point out that depending on HttpReferer might be a mistake.
Some popular firewall products strip always strip it out...conversly, you
aren't sure where users are going to be coming from, so make sure you
understand exactly what could happen with the code...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
G

Guest

The HttpReferer has the correct value and the iNews variable is set to TRUE
in the function but as soon as I try and get the value of iNews in the Sub
UpdateDocument the iNews value has reverted back to FALSE!

Can anyone tell me why!

Thanks
 
D

Damien

Tim::.. said:
The HttpReferer has the correct value and the iNews variable is set to TRUE
in the function but as soon as I try and get the value of iNews in the Sub
UpdateDocument the iNews value has reverted back to FALSE!

Can anyone tell me why!

Thanks
Are you, perhaps, settings the value during one web request (e.g., when
the page is first reached), and expecting the value to still be set
during a postback (e.g. reacting to user input on the form)?

I encounter this quite frequently with people who are new to the whole
ASP.NET experience - If this is the case, can I recommend that you go
on a bit of a google odyssey (I'd suggest the words ASP.NET and "Page
Lifecycle" for starters). Long answer short, the instance of your page
class that did the initial work was disposed of when the page was sent
to the client. It's a new instance of your class that is reacting to
the users input.

Damien
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top