Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net How to execute Page_Load One time

Posted on 2016-09-26
2
Medium Priority
?
92 Views
Last Modified: 2016-09-27
VB 2015

One the web page I have a list box that has 2 items added using Page_Load as follows

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ListBox1.Items.Add(New ListItem("Item1))
        ListBox1.Items.Add(New ListItem("Item2))
    End Sub

So the list box will have

Item1
Item2

In the same web page there is a button
Page_Load is executed every time a button is clicked

As a result List box is becoming

Item1
Item2
Item1
Item2

And Keeps on growing every time Button is clicked!    I discovered that Page_Load is loaded every time the button is clicked.
Is there a way to execute Page_Load once
0
Comment
Question by:saljas
[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
2 Comments
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 41816382
You want to check to see if the page is posting back or not; e.g. -
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	If Not Page.IsPostBack Then
		ListBox1.Items.Add(New ListItem("Item1))
		ListBox1.Items.Add(New ListItem("Item2))
	End If
End Sub

Open in new window


-saige-
0
 

Author Closing Comment

by:saljas
ID: 41817387
Many thanks
Exact answer
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

661 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