Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > 03 dropdownlist selectedindexchanged not firing in usercontrol on

Thread Tools

03 dropdownlist selectedindexchanged not firing in usercontrol on

Posts: n/a
I have a webform, click on link "one" and usercontrol page1.ascx loads.
Page1.ascx has the dropdrop list. The data loads when control first
displayed. The postback fires when item selected. The data does not do a
reload because of if !postback check. The value returned from the list is
always ""

Code from Page1.ascx

<aspropDownList EnableViewState="True" id="drpZone" AutoPostBack="True"

I am using session
protected string Zone
return Session["Zone"] as string;

Session["Zone"] = value;

Before the control renders if not postback I populate list with data
private void Page1_PreRender(object sender, EventArgs e)

Zone = drpZone.SelectedValue;

SearchBLL bll = new SearchBLL();


code from SearchBLL

public void ZoneData(Page1 pageControl)
SearchDAL dal = new SearchDAL();
pageControl.ZoneDataSource = dal.ZoneList();
code from SearchDAL
public DataSet ZoneList()
DataSet ds = new DataSet();
// Open database connection
SqlConnection connection = new SqlConnection("Data Source=tsbucontent;
Initial Catalog=sis_applications; uid=sa; pwd=1452hd;");
SqlCommand command = new SqlCommand();
// Create SQL command
string sql="SELECT ID,NAME FROM UserLU WHERE ACTIVE = '1' and TYPE =
SqlDataAdapter adapter = new SqlDataAdapter();
command.CommandText = sql;
command.Connection = connection;
adapter.SelectCommand = command;
// Fill Dataset
return ds;
catch //Error occured
//return null;
List is populated from database
I select value and postback happens, code does not go back to database to
repopulate I checked it. The event selectedindexchanged is never fired

code on Page1.ascx
private void InitializeComponent()
this.drpZone.SelectedIndexChanged +=new
this.btnRetrieve.Click += new System.EventHandler(this.btnRetrieve_Click);
this.dgResults.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgResults_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
this.PreRender += new System.EventHandler(this.Page1_PreRender);


private void drpZone_SelectedIndexChanged(object sender, EventArgs e)

SearchBLL bll = new SearchBLL();

cindy mello
Reply With Quote
Posts: n/a
Put this code in PageLoad instead of PreRender and bind it every time
(don't check IsPostback)

SearchBLL bll = new SearchBLL();

If you want to detect the OnChangeEvent you have to databind the
dropdown every time in page load. How else could ASP.NET know that the
index has changed if it didn't have the old values to compare it to?

You have to bind it in page load becuase the OnChangeEvent fires after
page load but *before* PreRender. If you want pointers to
documentation on the page lifecycle let me know.

-Sam Robertson

Reply With Quote
Steven Cheng[MSFT]
Posts: n/a
Hi Cindy,

Have you got a chance to check the suggestions and test page in my previous
message? If there're anything else we can help, please feel free to post
here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure!
(This posting is provided "AS IS", with no warranties, and confers no

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
dropdownlist selectedIndexChanged event not firing =?Utf-8?B?Q3VybHlGcm8=?= ASP .Net 1 08-14-2005 04:21 PM
DropDownList SelectedIndexChanged event not firing when in a panel Paul Lacey ASP .Net 2 02-17-2005 09:51 AM
SelectedIndexChanged event of a DropDownList sometimes not firing Lew Barnesson ASP .Net 3 12-04-2004 07:56 PM
DropDownList SelectedIndexChanged not firing for extra <form> =?Utf-8?B?R2Vvcmdl?= ASP .Net 4 09-08-2004 02:23 PM
dropdownlist selectedindexchanged event not firing.. please help. DesignerX ASP .Net 2 11-14-2003 03:25 PM