Boolean always false????

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

  1. 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
    =?Utf-8?B?VGltOjouLg==?=, Jul 25, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?VGltOjouLg==?=

    Clint Hill Guest

    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
    Clint Hill, Jul 25, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?VGltOjouLg==?=

    Karl Seguin Guest

    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" <> wrote in message
    news:...
    > 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
    Karl Seguin, Jul 25, 2005
    #3
  4. 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" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
    =?Utf-8?B?VGltOjouLg==?=, Jul 25, 2005
    #4
  5. =?Utf-8?B?VGltOjouLg==?=

    Damien Guest

    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
    Damien, Jul 25, 2005
    #5
  6. =?Utf-8?B?VGltOjouLg==?=

    Clint Hill Guest

    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
    >
    Clint Hill, Jul 25, 2005
    #6
    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. Andreas Klemt
    Replies:
    0
    Views:
    460
    Andreas Klemt
    Jul 4, 2003
  2. Vineet Jain
    Replies:
    2
    Views:
    336
    Mel Wilson
    Apr 12, 2004
  3. J Leonard
    Replies:
    4
    Views:
    12,625
    Mark Space
    Jan 19, 2008
  4. Replies:
    1
    Views:
    561
    Cowboy \(Gregory A. Beamer\)
    Nov 28, 2007
  5. Metre Meter
    Replies:
    7
    Views:
    355
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page