Results 1 to 6 of 6

Thread: Page_load

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Page_load

    I have this code, which works fine in my Page_load. But if I try to run the sub from SelectedIndexChanged then nothing happens. Do I have to specify something for my label like 'autopostback=true' for drpLists?
    Code:
    Protected Sub bindKappeDimension()
            If Not Page.IsPostBack Then
                Dim strCn As String = "Provider=Microsoft.jet.oledb.4.0;"
                strCn += "Data Source=" & Server.MapPath("priser04.MDB") & ";"
                Dim strSql As String = "Select Dim,Serie1 FROM SerieMat WHERE matId=" & intMatNr
                Dim strResultsHolder As Integer
    
                Dim objConnection As New OleDbConnection(strCn)
                Dim objCommand As New OleDbCommand(strSql, objConnection)
                Dim objDataReader As OleDbDataReader
    
                objConnection.Open()
                objDataReader = objCommand.ExecuteReader()
    
                Dim medieDim As Integer
                medieDim = CInt(Dim1.SelectedItem.Text)
    
                Do While objDataReader.Read() = True
                    strResultsHolder = objDataReader("Dim")
                    kappe1.Text = strResultsHolder
                Loop
    
    
                objDataReader.Close()
                objConnection.Close()
            End If
        End Sub

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Because it causes a post back when SelectIndexChanged fires.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    I usually only use IsPostback within Page_Load so that certain code is only run the 1st time the form is loaded.

    In your case, since the page has already been loaded at the time SelectedIndexChanged fires, the code inside the If Not IsPostback block will be bypassed.

    Does this make sense?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Hi, yes it does. Sorry, I just added the If Not IS.... when I tried to troubleshoot the sub. If I delete this nothing still happens. It has something to do with the Do While I think.

  5. #5
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    Well do you know for sure that the sub is called by SelectedIndexChanged? If you're not using Vis Studio and cannot debug try using response.write().

    You only need the AutoPostBack="True" if you want to post as soon as a new list item is selected.

    Also as you suggest it could well be that no rows are returned for the new query. It all depends on what intMatNr is...

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Post

    It worked when I use a Do While Loop and used Exit Do at the right place. But you were right, I've forgot to set the intMatNr. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width