Data is adding twice to the dropdown list under page load event

G

Guest

I have block of code adding values to dropdown list under

if (!Page.IsPostBack)
{
adding items
}
else
{
refreshing data
}
return


even I am checking !Page.IsPostBack, once its reaches to return, again it is
going to top of Page_Load event and executing true part of If block. So the
data is adding twice to the dropdown list.

One thing I do not understand is once the page is loaded, second time why
Page.IsPostBack is showing 'false'.

any help please, thanks in advance
 
N

Nicholas Paldino [.NET/C# MVP]

Tim,

You might want to set the combobox to not use viewstate to store it's
state, and rather, just populate the combobox every time you load the page.
You can cache the data for the list to make the operation faster as well.
Then, you can add items to the page based on the conditions that you
specify, and not the page state (which I don't think is a good model, to
base it on the page state, that is).

Hope this helps.
 
G

Guest

You mean that to set 'EnableViewState' property of the dropdownlist to
'false' I did that way, it did't help me out.
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

probably you are not postng back the page, if you have for example a link to
the same page that is a new request , not a refresh of the old one, use a
LinkButton instead.

post this:

what is the element in the page that do the request?

could you post the code for both the true and false blocks?


cheers,
 
G

Guest

I guess some of your code refresh the page in " refreshing data" function.
This may lead to Page_Load twice.
And at the second time of page load, the Page.IsPostBack is exactly true
since the old page and new page are same..
 
G

Guest

I can not post the code, it is huge. Apart from code do I need to set any
properties of page, control or config files. Please let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top