|
-
Dec 27th, 2006, 11:08 AM
#1
Thread Starter
Member
[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
-
Dec 27th, 2006, 11:35 AM
#2
Re: ispostback problems
You could use querystring to flag your child form from your main form. FYI this belongs in the asp.net forum.
-
Dec 27th, 2006, 12:43 PM
#3
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?
-
Dec 27th, 2006, 01:06 PM
#4
Thread Starter
Member
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
-
Dec 27th, 2006, 01:11 PM
#5
Thread Starter
Member
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
-
Dec 27th, 2006, 01:34 PM
#6
Thread Starter
Member
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
-
Dec 27th, 2006, 01:47 PM
#7
Thread Starter
Member
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
-
Dec 27th, 2006, 01:52 PM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 27th, 2006, 01:58 PM
#9
Thread Starter
Member
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:
Imports stockdataTableAdapters
Imports System.Drawing
Partial Class _Default
Inherits System.Web.UI.MobileControls.MobilePage
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
Protected Sub oblstRec_ItemSelect(ByVal sender As Object, ByVal e As System.Web.UI.MobileControls.ObjectListSelectEventArgs) Handles oblstRec.ItemSelect
Me.ActiveForm = Me.FrmUpd
lblpn.Text = e.ListItem.Item("PartNumber")
lblpna.Text = e.ListItem.Item("PartName")
lblc.Text = e.ListItem.Item("Condition")
lbll.Text = e.ListItem.Item("Location")
lblq.Text = e.ListItem.Item("Quantity")
lblv.Text = e.ListItem.Item("Valid")
If (lblv.Text = 0) Then
lblv.ForeColor = Color.Red
lblv.Text = "FALSE"
Else
lblv.ForeColor = Color.Green
lblv.Text = "TRUE"
End If
End Sub
Protected Sub cmdfind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdfind.Click
Dim allStock As New tbl_StockTableAdapter
oblstRec.DataSource = allStock.getstock(sltLoc.Selection.Value)
oblstRec.DataBind()
End Sub
Protected Sub cmdupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
Dim allStock As New tbl_StockTableAdapter
allStock.Updaterecord(txtpartn.Text, txtcon.Text, txtloc.Text, txtquan.Text, txtval.Text, lblpartn.Text)
Me.ActiveForm = Me.frmloc
End Sub
Protected Sub cmdcanc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdcanc.Click
Me.ActiveForm = Me.FrmUpd
End Sub
Protected Sub cmdedit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdedit.Click
Me.ActiveForm = Me.frmRes
lblpartn.Text = lblpn.Text
txtpartn.Text = lblpna.Text
txtcon.Text = lblc.Text
txtloc.Text = lbll.Text
txtquan.Text = lblq.Text
txtval.Text = lblv.Text
If (txtval.Text = "FALSE") Then
txtval.Text = 0
Else
txtval.Text = 1
End If
End Sub
Protected Sub cmdlback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdlback.Click
Me.ActiveForm = Me.frmloc
End Sub
Protected Sub cmdmssel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdmssel.Click
If (sltmsel.Selection.Value = "Location") Then
Me.ActiveForm = Me.frmloc
ElseIf (sltmsel.Selection.Value = "Name") Then
Me.ActiveForm = Me.frmloc
ElseIf (sltmsel.Selection.Value = "Number") Then
Me.ActiveForm = Me.frmloc
End If
End Sub
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
-
Dec 27th, 2006, 02:13 PM
#10
Thread Starter
Member
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
-
Dec 27th, 2006, 02:15 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 27th, 2006, 02:18 PM
#12
Re: IsPostBack Running Twice
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 27th, 2006, 02:19 PM
#13
Thread Starter
Member
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
-
Dec 27th, 2006, 02:23 PM
#14
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 27th, 2006, 02:29 PM
#15
Thread Starter
Member
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
-
Dec 27th, 2006, 02:37 PM
#16
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 27th, 2006, 03:09 PM
#17
Thread Starter
Member
Re: IsPostBack Running Twice
how do i resovle the thread
never done that im new
-
Dec 27th, 2006, 03:13 PM
#18
Thread Starter
Member
Re: IsPostBack Running Twice
found it thanks again for all your help
lee
-
Dec 27th, 2006, 03:13 PM
#19
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|