Event not firing

Discussion in 'ASP .Net' started by Doogie, Aug 20, 2007.

  1. Doogie

    Doogie Guest

    I'm sure it's just something I'm not seeing but for some reason, an
    event I have set up to be called when a combo box has been switched to
    a new value is not being fired for some reason and I can't figure out
    why. Below is my HTML.

    <%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="DataCreator.aspx.cs" Inherits="DataCreator" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:DropDownList ID="cbSqlServers" runat="server"
    <asp:DropDownList ID="cbDatabases" runat="server"

    and below is my code behind page (there are calls to other cs files,,
    that I'm not including here, if needed I can add them).

    Mainly I'm trying to figure out why in the GetSqlServers method, when
    the index value is changed it doesn't kick off
    cbSqlServers_SelectedIndexChanged. And it's not kicked off when I
    manually change the index value on the screen.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class DataCreator : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    private void GetSqlServers()
    string[] servers =

    foreach (string server in servers)

    if (cbSqlServers.Items.Count > 0)
    cbSqlServers.SelectedIndex = 0;

    protected void cbSqlServers_SelectedIndexChanged(object sender,
    EventArgs e)
    cbDatabases.Text = String.Empty;

    string sqlServer = cbSqlServers.SelectedItem.ToString();

    cbDatabases.DataSource =

    if (cbDatabases.Items.Count > 0)
    cbDatabases.SelectedIndex = 0;

    Doogie, Aug 20, 2007
    1. Advertisements

  2. I think you messed up ComboBoxes. One has AutoPostBack="True" but another
    has a SelectedIndexChanged assigned.
    Also set AutoEventWireup to "false". It will make you life easier.

    <asp:DropDownList ID="cbSqlServers" runat="server"

    George Ter-Saakov, Aug 20, 2007
    1. Advertisements

  3. Doogie

    Doogie Guest

    I think you messed up ComboBoxes. One has AutoPostBack="True" but another
    I had AutoPostback set to true by mistake there, I removed that, but
    it had no effect. The method still isn't being fired. (I do have the
    call to the method in the right spot though).

    What is AutoEventWireup? I tried to put that in as an attribute of my
    dropdown list, but the HTML complained it wasn't a valid attribute.
    Doogie, Aug 20, 2007
  4. Doogie

    Guest Guest

    Hi Doogie,
    when you change index manually in code behind file you also have to manually
    trigger your SelectIndexChanged handler. To allow triggering event by
    changing value in browser you also need to have some control which causes a
    postback - like button or set AutoPostBack = true on servers drop down.

    If you implement these changes your code will always ends with first server
    selected because you override index selected by user with 0 in each postback.
    You also do not clear server's drop down so values will be cumulated.


    Guest, Aug 21, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.