I have a user control dropdownlist, and its intended that when a user selects any item from dropdownlist , then accordingly image is displayed on the same form.

My problem is, when i select once from dropdownlist then , the page is going through the page_load and after clicking again the second time, it again walks through page_load and diretly displayes image

My question is, is it possible to avoid the page_load in any way ? & to load when i select the item first time from the dropdownlist ??

please help me to resolve this...

Recommended Answers

All 2 Replies

wrap your code in the page load event handler with the following:
if(!IsPostBack)
{
//your code
}

If you want the code inside the Page_load to execute just the first time the page loads and prevent it from executing subsequently, put this part of code inside an if not IsPostBack block

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

 If Not IsPostBack Then


' Code here that needs to be executed only on first page_load

End If
End Sub

IsPostBack is a Boolean property of a page when is set (=true) when a page is first loaded. Thus, the first time that the page loads the IsPostBack is false and for subsequent PostBacks, it is true.

Read more here: http://dotnet.tekyt.info/?p=30

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.