473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How are DropDown lists retained on postback?

I have an ASP.NET example which programmatically builds a drop down list.

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlCategories;

public class WebForm1 : System.Web.UI.Page
{
if (!IsPostBack)
{
// If page is requested for the first time
ddlCategories.Items.Add("Web development");
ddlCategories.Items.Add("Programming Languages");
ddlCategories.Items.Add("Certifications");
}

aString = ddlCategories.SelectedItem.ToString();
}

When it IS a postback, how is the Drop Down list populated?

I have confirmed that the drop down list is not populated in the .aspx file

I have disabled viewstate for the application, the list is still populated,
however the "SelectedItem" property is lost.

TIA
Dec 17 '06 #1
3 4242
Error in the top of the code. It should be...

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlCategories;

// --- error was here. fixed now. ---
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
.... etc...

"Javaman59" wrote:
I have an ASP.NET example which programmatically builds a drop down list.

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlCategories;

public class WebForm1 : System.Web.UI.Page
{
if (!IsPostBack)
{
// If page is requested for the first time
ddlCategories.Items.Add("Web development");
ddlCategories.Items.Add("Programming Languages");
ddlCategories.Items.Add("Certifications");
}

aString = ddlCategories.SelectedItem.ToString();
}

When it IS a postback, how is the Drop Down list populated?

I have confirmed that the drop down list is not populated in the .aspx file

I have disabled viewstate for the application, the list is still populated,
however the "SelectedItem" property is lost.

TIA

Dec 17 '06 #2
The values for the dropdown are already rendered and thus will be part of
the page - take a look at the source in the browser. Therefore, it doesn't
depend on viewstate. However, as you see, the selected item does depend on
viewstate since its a server control. That's why you still have the values
in the dropdown, but none of the control property information (which uses
viewstate). Its really not different than building a static web page (html)
and posting back - the values will still be there because they have already
been rendered.

"Javaman59" <Ja*******@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
>I have an ASP.NET example which programmatically builds a drop down list.

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlCategories;

public class WebForm1 : System.Web.UI.Page
{
if (!IsPostBack)
{
// If page is requested for the first time
ddlCategories.Items.Add("Web development");
ddlCategories.Items.Add("Programming Languages");
ddlCategories.Items.Add("Certifications");
}

aString = ddlCategories.SelectedItem.ToString();
}

When it IS a postback, how is the Drop Down list populated?

I have confirmed that the drop down list is not populated in the .aspx
file

I have disabled viewstate for the application, the list is still
populated,
however the "SelectedItem" property is lost.

TIA


Dec 17 '06 #3
Thanks Karch. That answers it for me.

"Karch" wrote:
The values for the dropdown are already rendered and thus will be part of
the page - take a look at the source in the browser. Therefore, it doesn't
depend on viewstate. However, as you see, the selected item does depend on
viewstate since its a server control. That's why you still have the values
in the dropdown, but none of the control property information (which uses
viewstate). Its really not different than building a static web page (html)
and posting back - the values will still be there because they have already
been rendered.

"Javaman59" <Ja*******@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
I have an ASP.NET example which programmatically builds a drop down list.

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlCategories;

public class WebForm1 : System.Web.UI.Page
{
if (!IsPostBack)
{
// If page is requested for the first time
ddlCategories.Items.Add("Web development");
ddlCategories.Items.Add("Programming Languages");
ddlCategories.Items.Add("Certifications");
}

aString = ddlCategories.SelectedItem.ToString();
}

When it IS a postback, how is the Drop Down list populated?

I have confirmed that the drop down list is not populated in the .aspx
file

I have disabled viewstate for the application, the list is still
populated,
however the "SelectedItem" property is lost.

TIA


Dec 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Mitchell | last post by:
My Goal is to have a dropdown (DL2) filled from the selectIndexChange event of a primary dropdown (DL1). These are picklists that will be selected frequently. Can someone recommend a strategy...
0
by: Toonman | last post by:
I have a webpage with a <form> consisting of a large table grid of dropdown lists used to make changes in a database. Some of these dropdown lists have the same value. I'm trying to make it so...
2
by: Tony Grider | last post by:
I am trying to find a way to create dependent dropdown lists in C# The old way I knew involved javascript and will no longer work in the new design. I need for each list to be database driven (data...
1
by: Mad Scientist Jr | last post by:
I don't know how this is happening, but a dropdown control I have is resetting to the 2nd value on the list anytime a postback occurs. I have no initiation code outside of If Not (IsPostBack) ...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
3
by: Jon | last post by:
I am using cascading dropdowns, where the selection in one determines what fills another. In regular ASP I simply loaded a giant dataset into javascript array and when you clicked on one dropdown,...
1
by: Ed Chiu | last post by:
Hi, I have 2 dropdown lists on an ASP.Net page, the first is a list of states of US, the second is City list. When user selects a state, the web page does a postback, create a DB connection and...
2
by: Brian | last post by:
Hi, All, I have two dropdown lists in itemtemplate in a datagrid. for example, dropA and dropB. also, for the dropdown, I set < Runat="server" AutoPostBack="True" OnSelectedIndexChanged="some...
3
by: John | last post by:
I have two dropdown lists that I have bound to a datatable and set the DataTextField and DataValueField for. Both lists show the values I expect from the database. However, when I need to access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.