Question

I have asp.net page with dynamic dropdown controls and I need only the selectedIndexchanged event to fire only for the user selection.

At present selectedIndexchanged event is firing for each programatically selection changes.

Can some one suggest how to check/fire the selectedIndexchanged event only the "User" selection?

Was it helpful?

Solution

I hope this work for you

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

    DropDownList cbTest = new DropDownList();
    cbTest.ID = "cbot";
    //create an event handler for the SelectedIndexChanged event
    cbTest.SelectedIndexChanged += new EventHandler(cbt_SelectedIndexChanged);        
    cbTest.Items.Add("1");
    cbTest.Items.Add("2");
    cbTest.Items.Add("3");
    //set the AutoPostBack property to sends the data back to the server
    cbTest.AutoPostBack = true;
    this.form1.Controls.Add(cbTest);

}
//handle the selections made by the User
void cbt_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Write("This works");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top