By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,630 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,630 IT Pros & Developers. It's quick & easy.

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

P: n/a
Tim
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
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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

Nov 16 '05 #2

P: n/a
Tim
You mean that to set 'EnableViewState' property of the dropdownlist to
'false' I did that way, it did't help me out.

"Tim" wrote:
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

Nov 16 '05 #3

P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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

Nov 16 '05 #4

P: n/a
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..

"Tim" wrote:
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

Nov 16 '05 #5

P: n/a
Tim
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.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
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


Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.