Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Boolean always false????

Reply
Thread Tools

Boolean always false????

 
 
=?Utf-8?B?VGltOjouLg==?=
Guest
Posts: n/a
 
      07-25-2005
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
 
Reply With Quote
 
 
 
 
Clint Hill
Guest
Posts: n/a
 
      07-25-2005
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

Tim::.. wrote:
> 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

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      07-25-2005
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!)
"Clint Hill" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> Tim::.. wrote:
>> 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



 
Reply With Quote
 
=?Utf-8?B?VGltOjouLg==?=
Guest
Posts: n/a
 
      07-25-2005
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

"Karl Seguin" wrote:

> 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!)
> "Clint Hill" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> > Tim::.. wrote:
> >> 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

>
>
>

 
Reply With Quote
 
Damien
Guest
Posts: n/a
 
      07-25-2005
Tim::.. wrote:
> 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

 
Reply With Quote
 
Clint Hill
Guest
Posts: n/a
 
      07-25-2005
Good call Damien.
Also try saving the value of iNews to ViewState. That would help too.

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

Damien wrote:
> Tim::.. wrote:
>
>>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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtle difference between boolean value and boolean comparison? Metre Meter Javascript 7 08-06-2010 08:40 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
web methods returning boolean : always returns false ndrw_cheung@yahoo.ca ASP .Net Web Services 1 11-28-2007 07:06 PM
Trying to create a CSS box that is always is always the width of an image placed inside it (and no wider) Deryck HTML 4 06-22-2004 08:25 PM
boolean to std_logic valentin tihomirov VHDL 3 01-05-2004 04:48 PM



Advertisments