Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with accessing function in page load Method

Newbie
 
Join Date: Jul 2008
Posts: 28
#1: Sep 8 '08
Hi All,

I am having a problem with accesing function in the page. i have a page say user.aspx in the page load method
i am calling function to validate the user.


it works fine when single user access the page but when another user try to access the page then it crash the
first users processing and empty the session variable.

means when i am calling function in the page load of user.aspx then it is giving me problem.
and if i write user validation code direct in page load method then it works fine.

problem occurs only when i write user validation code in function and try to call that function in page load of
user.aspx

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Page_Load
  2.  
  3.  
  4.  
  5.       IF validateUser() THEN      
  6.  
  7.               Response.write ("Welcome" & sUserID )
  8.     Else
  9.             Response.Redirect("UserNotFound.aspx?userid=" & sUserID & "&Form=DataXS")
  10.        End If
  11.  
  12.  
  13.  End sub
  14.  
  15.  
  16.  Public Function validateUser() as boolean
  17.  
  18.     Dim dbOleDbDataReader As OleDbDataReader
  19.     dim bflag as boolen
  20.  
  21.                         sSQL = "Select NAME From kuaf where lower(NAME)='" & LCase(sUserID) & "' 
  22.  
  23.                         Dim sConnectionString As String = xsData.getDatabaseConnection(sLogFile)
  24.                         Using dbConnection As New OleDbConnection(sConnectionString)
  25.                             Dim dbcommand As New OleDbCommand(sSQL, dbConnection)
  26.                             dbcommand.CommandType = CommandType.Text
  27.                             dbcommand.Connection.Open()
  28.                             dbOleDbDataReader = dbcommand.ExecuteReader()
  29.  
  30.                             If Not dbOleDbDataReader Is Nothing Then
  31.                                 If dbOleDbDataReader.Read() Then
  32.                     bflag = True
  33.                                 Else
  34.                                     Response.Redirect("UserNotFound.aspx?userid=" & sUserID & "&Form=DataXS")
  35.                                 End If
  36.                             End If
  37.  
  38.                             dbOleDbDataReader.Close()
  39.                             dbOleDbDataReader = Nothing
  40.                             dbcommand.Dispose()
  41.                             dbcommand = Nothing
  42.                             dbConnection.Close()
  43.                         End Using
  44.  
  45.     Return bflag 
  46.  
  47.  End Function 
can u tell me why it is happening..

Thanks

-Joseph

kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Sep 8 '08

re: Problem with accessing function in page load Method


If boolean value true or false. Return result first and then test whether the result is t or f. However I notice you have a typo in declaring bflag.
Reply