Results 1 to 19 of 19

Thread: [RESOLVED] IsPostBack Running Twice

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Resolved [RESOLVED] IsPostBack Running Twice

    Hi there I am using
    if not IsPostBack then
    to check if a list box is loaded for the first time
    this worked fine when the page was the main form

    Protected Sub frmloc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmloc.Load
    Dim locations As New tbllocAdapter
    Dim allStock As New tbl_StockTableAdapter
    If Not IsPostBack Then
    sltLoc.DataSource = locations.faetlocdata
    sltLoc.DataValueField = "Location"
    sltLoc.DataTextField = "Location"
    sltLoc.DataBind()
    Else
    oblstRec.DataSource = allStock.getstock(sltLoc.Selection.Value)
    oblstRec.DataBind()
    End If
    End Sub

    but now i have a main screen that selects this form from a drop down list(search criteria)
    by dowing this it now trys to run the else statment when the page is first loaded which of course from the code is trying to load an object list that has been created yet as the list is poulated when an option from the dropdown is selected.

    Like I said this worked whne the page was the main form but now it is not it seems to ignore the not IsPostBack and go to the else straigth away
    anyone have any ideas
    lee

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: ispostback problems

    You could use querystring to flag your child form from your main form. FYI this belongs in the asp.net forum.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: IsPostBack Running Twice

    did you set a break point on your form load and step through while you are running it to see whats going on?

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    Hi there
    yes tried running a break point, was hard to do pages took ages to load, not sure why though it would run as normal, what happen was that the IfPostBack is populating the dropdownlist as it should but it is then also running the else part of the stament as well which of course wont run unless it is a postback.
    any ideas
    lee

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    it seams to be running all the code in the loadevent and ignoring the if statment arround the code, that how it appears anyway when I run through it, this only happen when I added another form that activates that form by me.activeform = frmsel, if i run the form direct as the first form to load it works

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    I found what is happening but no idea why the load event for frmsel is loadinf first when form frmmain is loaded and then again when form frmsel is loaded thats why it thinks it is a postback when frmsel loads, anyone know why the load event for frmsel would load when frmmain runs, I do not have a load event at all for the frmmain so i am not calling it by accident
    any ideas
    lee

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: ispostback problems

    I have worked out what is wron, the form frmsel's load event is running when the page first loads, and not just whne the form loads, have no idea why though anyone have any ideas
    lee

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ispostback problems

    If the page is loading from some postback event raised by a control on the page then the .IsPostback will = True.

    Moved.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: ispostback problems

    this is my full code, for some reason the frmloc load event is loading when the page loads and again when the form loads the first form to load is frmmain which does not run anything on load, but the frmloc load function still runs.
    see what u think
    VB Code:
    1. Imports stockdataTableAdapters
    2. Imports System.Drawing
    3. Partial Class _Default
    4.     Inherits System.Web.UI.MobileControls.MobilePage
    5.  
    6.     Protected Sub frmloc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmloc.Load
    7.         Dim locations As New tbllocAdapter
    8.         Dim allStock As New tbl_StockTableAdapter
    9.         If Not IsPostBack Then
    10.             sltLoc.DataSource = locations.faetlocdata
    11.             sltLoc.DataValueField = "Location"
    12.             sltLoc.DataTextField = "Location"
    13.             sltLoc.DataBind()
    14.         Else
    15.             oblstRec.DataSource = allStock.getstock(sltLoc.Selection.Value)
    16.             oblstRec.DataBind()
    17.         End If
    18.     End Sub
    19.  
    20.  
    21.     Protected Sub oblstRec_ItemSelect(ByVal sender As Object, ByVal e As System.Web.UI.MobileControls.ObjectListSelectEventArgs) Handles oblstRec.ItemSelect
    22.         Me.ActiveForm = Me.FrmUpd
    23.         lblpn.Text = e.ListItem.Item("PartNumber")
    24.         lblpna.Text = e.ListItem.Item("PartName")
    25.         lblc.Text = e.ListItem.Item("Condition")
    26.         lbll.Text = e.ListItem.Item("Location")
    27.         lblq.Text = e.ListItem.Item("Quantity")
    28.         lblv.Text = e.ListItem.Item("Valid")
    29.  
    30.         If (lblv.Text = 0) Then
    31.             lblv.ForeColor = Color.Red
    32.             lblv.Text = "FALSE"
    33.         Else
    34.             lblv.ForeColor = Color.Green
    35.             lblv.Text = "TRUE"
    36.         End If
    37.  
    38.     End Sub
    39.  
    40.     Protected Sub cmdfind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdfind.Click
    41.         Dim allStock As New tbl_StockTableAdapter
    42.         oblstRec.DataSource = allStock.getstock(sltLoc.Selection.Value)
    43.         oblstRec.DataBind()
    44.  
    45.     End Sub
    46.  
    47.     Protected Sub cmdupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
    48.         Dim allStock As New tbl_StockTableAdapter
    49.         allStock.Updaterecord(txtpartn.Text, txtcon.Text, txtloc.Text, txtquan.Text, txtval.Text, lblpartn.Text)
    50.         Me.ActiveForm = Me.frmloc
    51.     End Sub
    52.  
    53.     Protected Sub cmdcanc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdcanc.Click
    54.         Me.ActiveForm = Me.FrmUpd
    55.     End Sub
    56.  
    57.  
    58.     Protected Sub cmdedit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdedit.Click
    59.         Me.ActiveForm = Me.frmRes
    60.         lblpartn.Text = lblpn.Text
    61.         txtpartn.Text = lblpna.Text
    62.         txtcon.Text = lblc.Text
    63.         txtloc.Text = lbll.Text
    64.         txtquan.Text = lblq.Text
    65.         txtval.Text = lblv.Text
    66.         If (txtval.Text = "FALSE") Then
    67.             txtval.Text = 0
    68.         Else
    69.             txtval.Text = 1
    70.         End If
    71.  
    72.     End Sub
    73.  
    74.     Protected Sub cmdlback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdlback.Click
    75.         Me.ActiveForm = Me.frmloc
    76.     End Sub
    77.  
    78.     Protected Sub cmdmssel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdmssel.Click
    79.         If (sltmsel.Selection.Value = "Location") Then
    80.             Me.ActiveForm = Me.frmloc
    81.         ElseIf (sltmsel.Selection.Value = "Name") Then
    82.             Me.ActiveForm = Me.frmloc
    83.         ElseIf (sltmsel.Selection.Value = "Number") Then
    84.             Me.ActiveForm = Me.frmloc
    85.         End If
    86.     End Sub
    87.  
    88. End Class

    I do call the formloc from a selection in a dropdown list on frmmain, if this does mean that postback will then be set to true how do i get the dropdown list on frmloc to only load once
    hope i am making sence im new to this
    lee
    Last edited by RobDog888; Dec 27th, 2006 at 02:13 PM. Reason: Added [vbcode] tags

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: ispostback problems

    I have change the load event to a form activate event and it does not run twice anymore, but when the frmloc activate event load postback is true when it should be false as the form has just loaded. I know as i actvated the form from a cmdbutton on another page that postback is the set to true but i need it to be false the first time the form loads as to only poulate the dropdown list once the display the data everyother time.
    any ideas
    lee

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ispostback problems

    Yes, if it is being called from the dropdown on frmmain then it will generate a postback.

    Maybe check that the listbox contains any items instead?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: IsPostBack Running Twice

    Threads merged.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    Hi there thanks for the reply you are right thats what i need to do, do you know how i can check if a dropdown list holds any data or not not sure on that one
    lee

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: IsPostBack Running Twice

    Should be an ddl.Items.Count property to check for > 0
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    Thats it it work, thanks ever so much there is no way I coulkd have worked that out my self that brilliant
    thanks allot
    lee

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: IsPostBack Running Twice

    Glad its working now.

    Ps, dont forget to Resolve your thread.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    how do i resovle the thread
    never done that im new

  18. #18

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: IsPostBack Running Twice

    found it thanks again for all your help
    lee

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: IsPostBack Running Twice

    use the thread tools menu above (my signature has a screen shot of it)

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