03 dropdownlist selectedindexchanged not firing in usercontrol on

Discussion in 'ASP .Net Web Controls' started by cindy, Jun 6, 2005.

  1. cindy

    cindy Guest

    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

    <asp:DropDownList EnableViewState="True" id="drpZone" AutoPostBack="True"
    runat="server"></asp:DropDownList>

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

    set
    {
    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();
    bll.ZoneData(this);

    }

    code from SearchBLL

    public void ZoneData(Page1 pageControl)
    {
    SearchDAL dal = new SearchDAL();
    pageControl.ZoneDataSource = dal.ZoneList();
    }
    code from SearchDAL
    public DataSet ZoneList()
    {
    try
    {
    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 =
    'Zone'";
    SqlDataAdapter adapter = new SqlDataAdapter();
    command.CommandText = sql;
    command.Connection = connection;
    adapter.SelectCommand = command;
    // Fill Dataset
    adapter.Fill(ds);
    return ds;
    }
    catch //Error occured
    {
    throw;
    //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
    EventHandler(drpZone_SelectedIndexChanged);
    this.btnRetrieve.Click += new System.EventHandler(this.btnRetrieve_Click);
    this.dgResults.ItemCommand += new
    System.Web.UI.WebControls.DataGridCommandEventHandler(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();
    bll.LCTData(this);
    }




    --
    cindy mello
     
    cindy, Jun 6, 2005
    #1
    1. Advertising

  2. cindy

    sam Guest

    Put this code in PageLoad instead of PreRender and bind it every time
    (don't check IsPostback)

    SearchBLL bll = new SearchBLL();
    bll.ZoneData(this);

    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
     
    sam, Jun 6, 2005
    #2
    1. Advertising

  3. 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! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 9, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DesignerX
    Replies:
    2
    Views:
    3,868
    Bob Carsto
    Nov 14, 2003
  2. Paul Lacey
    Replies:
    2
    Views:
    2,721
    =?Utf-8?B?TmlrYW5kZXIgJiBNYXJncmlldCBCcnVnZ2VtYW4=
    Feb 17, 2005
  3. =?Utf-8?B?R2Vvcmdl?=
    Replies:
    4
    Views:
    3,736
    =?Utf-8?B?SmVyZW15IERhdmlz?=
    Sep 8, 2004
  4. Lew Barnesson
    Replies:
    3
    Views:
    823
    Lew Barnesson
    Dec 4, 2004
  5. =?Utf-8?B?Q3VybHlGcm8=?=

    dropdownlist selectedIndexChanged event not firing

    =?Utf-8?B?Q3VybHlGcm8=?=, Aug 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,640
    =?Utf-8?B?Q3VybHlGcm8=?=
    Aug 14, 2005
Loading...

Share This Page