A big problem in dropdownlist web control

P

Pedro Airo

I had done the following code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack){
DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
}
}

and

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int idx = DropDownList1.Items.Count;
DropDownList1.Items.Add("Item: " + idx);
}

In a pc with a win xp the aspx works just fine, but when i put this aspx in
a win 2003 iis , the progra in the first time works fine, when i click in a
dropdownlist item, the dropdownlist will be empty.

Anyone can help me?
 
J

John Saunders

Pedro Airo said:
I had done the following code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack){
DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
}
}

and

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int idx = DropDownList1.Items.Count;
DropDownList1.Items.Add("Item: " + idx);
}

In a pc with a win xp the aspx works just fine, but when i put this aspx
in
a win 2003 iis , the progra in the first time works fine, when i click in
a
dropdownlist item, the dropdownlist will be empty.

Anyone can help me?

You can probably help yourself.

Take a look at the generated HTML with View Source. Do it when you first
request the page, then do it on the resulting page after selecting from the
DropDownList. Try it on the W2K3 machine and if necessary, on the WXP
machine.

In particular, see if the __VIEWSTATE hidden field is markedly different.

John Saunders
 
S

SevDer

Pedro said:
I had done the following code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack){
DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
}
}

and

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int idx = DropDownList1.Items.Count;
DropDownList1.Items.Add("Item: " + idx);
}

In a pc with a win xp the aspx works just fine, but when i put this aspx in
a win 2003 iis , the progra in the first time works fine, when i click in a
dropdownlist item, the dropdownlist will be empty.

Anyone can help me?
I am exactly having the same problem.
See my post "DropDownList viewstate does not work" posted yesterday.

Currently when a postback occurs, I am loading all the user selections
into viewstate manually and assigning them back to controls after
rebinding in page_load method.

Here is example code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//this saves user selections to user controls and must
//be fired from the postback generator method as the
//first thing
public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("ddYear",ddYear.SelectedValue);
ViewState.Add("ddState",ddState.SelectedValue);
ViewState.Add("ddSState",ddSState.SelectedValue);
ViewState.Add("ddCountry",ddCountry.SelectedValue);
ViewState.Add("ddSCountry",ddSCountry.SelectedValue);
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void Page_Load(object sender, System.EventArgs e)
{

BindStaticControls();
LoadUserSelectionsFromViewState();
}//end Page_Load method

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void LoadUserSelectionsFromViewState()
{
if (ViewState["ddYear"] != null)
ddYear.SelectedValue = ViewState["ddYear"].ToString();
if (ViewState["ddState"] != null)
ddState.SelectedValue = ViewState["ddState"].ToString();
if (ViewState["ddSState"] != null)
ddSState.SelectedValue = ViewState["ddSState"].ToString();
if (ViewState["ddCountry"] != null)
ddCountry.SelectedValue = ViewState["ddCountry"].ToString();
if (ViewState["ddSCountry"]!= null)
ddSCountry.SelectedValue= ViewState["ddSCountry"].ToString();
}

If anybody has an elegant solution please let me know too.
 
P

Pedro Airo

Tnkz for the response, but at this moment my problem still not be resolved,
the code that i had write is the following:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("Item 1");
DropDownList1.Items.Add("Item 2");
}
else
LoadUserSelectionsFromViewState();
}

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DropDownList1.Items.Add("Item " + DropDownList1.Items.Count);
SaveUserSelectionsIntoViewState();
}

public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("DropDownList1",DropDownList1.SelectedValue);
}

private void LoadUserSelectionsFromViewState()
{
if (ViewState["DropDownList1"] != null)
DropDownList1.SelectedValue = ViewState["DropDownList1"].ToString();
}

And the Dropdownlist have the autopostback attribute TRUE.

I don't understand.

Another thing, i have compare the viewstate at the win xp machine and at the
win2003, and they are different.

Regards, Pedro Airo

SevDer said:
Pedro said:
I had done the following code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack){
DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
}
}

and

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int idx = DropDownList1.Items.Count;
DropDownList1.Items.Add("Item: " + idx);
}

In a pc with a win xp the aspx works just fine, but when i put this aspx in
a win 2003 iis , the progra in the first time works fine, when i click in a
dropdownlist item, the dropdownlist will be empty.

Anyone can help me?
I am exactly having the same problem.
See my post "DropDownList viewstate does not work" posted yesterday.

Currently when a postback occurs, I am loading all the user selections
into viewstate manually and assigning them back to controls after
rebinding in page_load method.

Here is example code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//this saves user selections to user controls and must
//be fired from the postback generator method as the
//first thing
public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("ddYear",ddYear.SelectedValue);
ViewState.Add("ddState",ddState.SelectedValue);
ViewState.Add("ddSState",ddSState.SelectedValue);
ViewState.Add("ddCountry",ddCountry.SelectedValue);
ViewState.Add("ddSCountry",ddSCountry.SelectedValue);
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void Page_Load(object sender, System.EventArgs e)
{

BindStaticControls();
LoadUserSelectionsFromViewState();
}//end Page_Load method

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void LoadUserSelectionsFromViewState()
{
if (ViewState["ddYear"] != null)
ddYear.SelectedValue = ViewState["ddYear"].ToString();
if (ViewState["ddState"] != null)
ddState.SelectedValue = ViewState["ddState"].ToString();
if (ViewState["ddSState"] != null)
ddSState.SelectedValue = ViewState["ddSState"].ToString();
if (ViewState["ddCountry"] != null)
ddCountry.SelectedValue = ViewState["ddCountry"].ToString();
if (ViewState["ddSCountry"]!= null)
ddSCountry.SelectedValue= ViewState["ddSCountry"].ToString();
}

If anybody has an elegant solution please let me know too.
 
S

SevDer

Pedro said:
Tnkz for the response, but at this moment my problem still not be resolved,
the code that i had write is the following:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("Item 1");
DropDownList1.Items.Add("Item 2");
}
else
LoadUserSelectionsFromViewState();
}

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DropDownList1.Items.Add("Item " + DropDownList1.Items.Count);
SaveUserSelectionsIntoViewState();
}

public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("DropDownList1",DropDownList1.SelectedValue);
}

private void LoadUserSelectionsFromViewState()
{
if (ViewState["DropDownList1"] != null)
DropDownList1.SelectedValue = ViewState["DropDownList1"].ToString();
}

And the Dropdownlist have the autopostback attribute TRUE.

I don't understand.

Another thing, i have compare the viewstate at the win xp machine and at the
win2003, and they are different.

Regards, Pedro Airo

:

Pedro said:
I had done the following code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack){
DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
}
}

and

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int idx = DropDownList1.Items.Count;
DropDownList1.Items.Add("Item: " + idx);
}

In a pc with a win xp the aspx works just fine, but when i put this aspx in
a win 2003 iis , the progra in the first time works fine, when i click in a
dropdownlist item, the dropdownlist will be empty.

Anyone can help me?

I am exactly having the same problem.
See my post "DropDownList viewstate does not work" posted yesterday.

Currently when a postback occurs, I am loading all the user selections
into viewstate manually and assigning them back to controls after
rebinding in page_load method.

Here is example code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//this saves user selections to user controls and must
//be fired from the postback generator method as the
//first thing
public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("ddYear",ddYear.SelectedValue);
ViewState.Add("ddState",ddState.SelectedValue);
ViewState.Add("ddSState",ddSState.SelectedValue);
ViewState.Add("ddCountry",ddCountry.SelectedValue);
ViewState.Add("ddSCountry",ddSCountry.SelectedValue);
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void Page_Load(object sender, System.EventArgs e)
{

BindStaticControls();
LoadUserSelectionsFromViewState();
}//end Page_Load method

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void LoadUserSelectionsFromViewState()
{
if (ViewState["ddYear"] != null)
ddYear.SelectedValue = ViewState["ddYear"].ToString();
if (ViewState["ddState"] != null)
ddState.SelectedValue = ViewState["ddState"].ToString();
if (ViewState["ddSState"] != null)
ddSState.SelectedValue = ViewState["ddSState"].ToString();
if (ViewState["ddCountry"] != null)
ddCountry.SelectedValue = ViewState["ddCountry"].ToString();
if (ViewState["ddSCountry"]!= null)
ddSCountry.SelectedValue= ViewState["ddSCountry"].ToString();
}

If anybody has an elegant solution please let me know too.
Hi Pedro,

I've solved my problem.
My dropdowns were in a panel, and my panel's viewstate was disabled.
After enabling viewstate of the panel, it started to work.

as a first step, try to move your dropdown to the end or begining of the
form, may be you have a similar problem. If it doesn't work, send me an
email with more details.
 
P

Pedro Airo

I only have in the page the dropdownlist, i had tried to put the drop down
list in a panel with the viewstate enable, and nothing new happen.

Regards, Pedro Airo

SevDer said:
Pedro said:
Tnkz for the response, but at this moment my problem still not be resolved,
the code that i had write is the following:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Add("Item 1");
DropDownList1.Items.Add("Item 2");
}
else
LoadUserSelectionsFromViewState();
}

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
DropDownList1.Items.Add("Item " + DropDownList1.Items.Count);
SaveUserSelectionsIntoViewState();
}

public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("DropDownList1",DropDownList1.SelectedValue);
}

private void LoadUserSelectionsFromViewState()
{
if (ViewState["DropDownList1"] != null)
DropDownList1.SelectedValue = ViewState["DropDownList1"].ToString();
}

And the Dropdownlist have the autopostback attribute TRUE.

I don't understand.

Another thing, i have compare the viewstate at the win xp machine and at the
win2003, and they are different.

Regards, Pedro Airo

:

Pedro Airo wrote:

I had done the following code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack){
DropDownList1.Items.Add("Item1");
DropDownList1.Items.Add("Item2");
}
}

and

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
int idx = DropDownList1.Items.Count;
DropDownList1.Items.Add("Item: " + idx);
}

In a pc with a win xp the aspx works just fine, but when i put this aspx in
a win 2003 iis , the progra in the first time works fine, when i click in a
dropdownlist item, the dropdownlist will be empty.

Anyone can help me?


I am exactly having the same problem.
See my post "DropDownList viewstate does not work" posted yesterday.

Currently when a postback occurs, I am loading all the user selections
into viewstate manually and assigning them back to controls after
rebinding in page_load method.

Here is example code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//this saves user selections to user controls and must
//be fired from the postback generator method as the
//first thing
public void SaveUserSelectionsIntoViewState()
{
ViewState.Add("ddYear",ddYear.SelectedValue);
ViewState.Add("ddState",ddState.SelectedValue);
ViewState.Add("ddSState",ddSState.SelectedValue);
ViewState.Add("ddCountry",ddCountry.SelectedValue);
ViewState.Add("ddSCountry",ddSCountry.SelectedValue);
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void Page_Load(object sender, System.EventArgs e)
{

BindStaticControls();
LoadUserSelectionsFromViewState();
}//end Page_Load method

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

private void LoadUserSelectionsFromViewState()
{
if (ViewState["ddYear"] != null)
ddYear.SelectedValue = ViewState["ddYear"].ToString();
if (ViewState["ddState"] != null)
ddState.SelectedValue = ViewState["ddState"].ToString();
if (ViewState["ddSState"] != null)
ddSState.SelectedValue = ViewState["ddSState"].ToString();
if (ViewState["ddCountry"] != null)
ddCountry.SelectedValue = ViewState["ddCountry"].ToString();
if (ViewState["ddSCountry"]!= null)
ddSCountry.SelectedValue= ViewState["ddSCountry"].ToString();
}

If anybody has an elegant solution please let me know too.
Hi Pedro,

I've solved my problem.
My dropdowns were in a panel, and my panel's viewstate was disabled.
After enabling viewstate of the panel, it started to work.

as a first step, try to move your dropdown to the end or begining of the
form, may be you have a similar problem. If it doesn't work, send me an
email with more details.
 

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

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top