467,073 Members | 1,249 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,073 developers. It's quick & easy.

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

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
  • viewed: 2672
Share:
5 Replies
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
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
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
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
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.

Similar topics

reply views Thread by anonymous | last post: by
2 posts views Thread by Sam Kuehn | last post: by
4 posts views Thread by Chris | last post: by
2 posts views Thread by Mike Collins | last post: by
5 posts views Thread by docw@globetrotter.net | last post: by
3 posts views Thread by tarscher@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.