Solved

VB.net How to execute Page_Load One time

Posted on 2016-09-26
2
80 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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