Solved

Why is IsPostBack always = False

Posted on 2004-09-07
10
1,725 Views
Last Modified: 2008-02-01
I have a problem with the following code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then

            Try

                Dim strUserInfo() As String

                strUserInfo = Split(Me.Request.ServerVariables("LOGON_USER").ToString(), "\")

                strCurrentUser = strUserInfo(1)
                strCurrentDomain = strUserInfo(0)
             
            Catch ex As Exception
                strCurrentUser = ""
            End Try
        End if
End sub

The code is always executed because IsPostback = False. The page also includes a Asp:Button. According to al awailable documentation ispostback is false only the first time the page is loaded.
0
Comment
Question by:anpr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 11996039
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IsPostBack Then

            Try

                Dim strUserInfo() As String

                strUserInfo = Split(Me.Request.ServerVariables("LOGON_USER").ToString(), "\")

                strCurrentUser = strUserInfo(1)
                strCurrentDomain = strUserInfo(0)
             
            Catch ex As Exception
                strCurrentUser = ""
            End Try
        End if
End sub
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11996046
post the code for your Button onClick event
0
 

Author Comment

by:anpr
ID: 11996143
Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        UpdateSchedule()
   
End Sub

The btnUpdate_Click simply cals a function called UpdateSchedule. This part works fine.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 35

Expert Comment

by:YZlat
ID: 11996261
let me see the code for update schedule. The reason why the page is not posting back might be there.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11996283
also what exactly do you want to do? meaning when do you want your code to execute, under what circumstances
0
 

Author Comment

by:anpr
ID: 11996421
   Private Function UpdateSchedule()

        Dim intCount As Integer
        Dim NewRow As New TableRow
        Dim strLabel As String
        Dim strsql As String
        Dim rs As New ADODB.Recordset
        Dim Monday As Date
        Dim strMonday As String
        Dim Friday As Date
        Dim strFriday As String

        For intCount = 0 To 5
            Dim NewCell As New TableCell
            NewCell.BorderStyle = BorderStyle.Solid

            If intCount = 0 Then
                strLabel = "Time"
            ElseIf intCount = 1 Then
                strLabel = "Monday   "
            ElseIf intCount = 2 Then
                strLabel = "Tuesday  "
            ElseIf intCount = 3 Then
                strLabel = "Wednesday"
            ElseIf intCount = 4 Then
                strLabel = "Thursday "
            ElseIf intCount = 5 Then
                strLabel = "Friday   "
            End If

            NewCell.Controls.Add(New LiteralControl(strLabel & ":"))
            NewRow.Cells.Add(NewCell)
        Next
        NewRow.Font.Bold = True
        NewRow.ForeColor = Color.Blue

        Me.TblSchedule.Rows.Add(NewRow)


        Monday = Now.Date.AddDays(-intCurrentDayOfWeek + 1)
        Friday = Monday.AddDays(4)
        strMonday = Monday.Month & "/" & Monday.Day & "/" & Monday.Year
        strFriday = Friday.Month & "/" & Friday.Day & "/" & Friday.Year

        For intCount = intCurrentWeekNo To intSelectedWeekNo

        Next

        strsql = "SELECT StartTime, EndTime, Subject, Location" _
            & " FROM Appointments WHERE mailbox = '" & CStr(ddlInitials.SelectedValue) & "@mail'" _
            & " AND StartTime >='" & strMonday & "'" _
            & " AND StartTime <= '" & strFriday & "' ORDER BY StartTime asc"

        rs = myDB.SQLAceessToDB(strsql)

        Dim intDayCount As Integer
        Dim dateWork As Date
        Dim ts As TimeSpan
        dateWork = Monday

        For intCount = 0 To 8 Step 2
            Dim NewScheduleRow As New TableRow
            dateWork.AddHours(intCount)
            Dim newTimeCell As New TableCell
            Dim intTime As Integer
            intTime = 8 + intCount
            newTimeCell.Controls.Add(New LiteralControl(CStr(intTime) & " -"))
            newTimeCell.BorderStyle = BorderStyle.Solid
            NewScheduleRow.Cells.Add(newTimeCell)

            For intDayCount = 0 To 4
                Dim StartTime As Date
                Dim EndTime As Date
                Dim newScheduleCell As New TableCell
                Dim dateDB As Date
                Dim strSchedule As String

                newScheduleCell.BorderStyle = BorderStyle.Solid

                Try
                    While Not rs.EOF
                        dateDB = rs.Fields("StartTime").Value
                        If dateWork.Date = dateDB.Date Then
                            strSchedule = rs.Fields("Subject").Value
                        End If
                        rs.MoveNext()
                    End While

                Catch
                End Try
                dateWork = dateWork.AddDays(1)

                If Len(strSchedule) = 0 Then strSchedule = "-"
                newScheduleCell.Controls.Add(New LiteralControl(strSchedule))
                NewScheduleRow.Cells.Add(newScheduleCell)
                strSchedule = ""
                Try
                    rs.MoveFirst()
                Catch
                End Try

            Next

            Me.TblSchedule.Rows.Add(NewScheduleRow)

        Next
        Try
            rs.Close()
        Catch
        End Try

    End Function

The application contains two dropdownlist. One with weeknumber and another one with initialts. The users can use this application to se their schedule in the different weeknumbers.
The application will by default show the schedule for the current week and for the current ADS user. The Initials and the schedule tasks are picked up in a SQL database.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11996692
I have a suggestion to make:

1)Delete the code for button click

2)Replace your Page_Load with the following code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IsPostBack Then

                  Try

                      Dim strUserInfo() As String

                      strUserInfo = Split(Me.Request.ServerVariables("LOGON_USER").ToString(), "\")

                      strCurrentUser = strUserInfo(1)
                      strCurrentDomain = strUserInfo(0)
             
                  Catch ex As Exception
                      strCurrentUser = ""
                  End Try
      Else
            UpdateSchedule()

      End if
End Sub
0
 

Author Comment

by:anpr
ID: 11996819
For some reason there is an effect. IsPostBack is now true at the second load. Can you explain me the differens in the two samples?
0
 
LVL 35

Accepted Solution

by:
YZlat earned 50 total points
ID: 11996987
because postback event occurs before button click event.

Read this article, it explains a lot about event .NET programming
http://64.233.167.104/search?q=cache:P9GuRRzxNrwJ:www.personal.psu.edu/faculty/j/a/jat14/misbd470/Event%2520driven%2520Programming%2520and%2520Postback.doc
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11999536
PostBack occurs when an ASP.NET form in a page has been posted back to the server, such as via a click on a submit button, or an AutoPostBack trigger.

PostBack does not occur if the page simply redirects onto itself (forming a new "first" request"), or is re-achieved via any method other than the submission of its ASP.NET form.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question