Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have asp.net page with dynamic dropdown controls and I need only the
C#
selectedIndexchanged 
event to fire only for the user selection.

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

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

The Solution provided by Marcus Kramer is working fine.
"Do something similar to this on the client-side with javascript where you effectively intercept the selectedindexchanged event for the dropdownlist and decide on the client side whether or not to let the postback occur. That is if you can attach a handler to the other dynamic control that could manage a "IamDoingSomething" flag in javascript."
 
Share this answer
 
If you are going to change the value programmatically, you can set a flag in your class that you check in the selectedIndexChanged event...
C#
private bool _iAmDoingSomething = false;
private void DoSomething()
{
   _iAmDoingSomething = true;
   YourDropDownControl.SelectedIndex = newIndex;
   _iAmDoingSomething = false;
}

private void SelectedIndexChangedHandler(...)
{
   if( _iAmDoingSomething )
      return;
   
   // Do the rest of your handler code.
}
 
Share this answer
 
Comments
Milan Mathew 16-Oct-12 16:31pm    
Already tried this but this changes are happening in a dynamic control and its firing another selected index changed for each of the value changes and no way we can identify the user selection.

I need to call the selectedindexchanged only based on user selection (manual).
fjdiewornncalwe 16-Oct-12 16:37pm    
There is always a way. :)
This is good extra information that we didn't have. You could also do something similar to this on the client-side with javascript where you effectively intercept the selectedindexchanged event for the dropdownlist and decide on the client side whether or not to let the postback occur. That is if you can attach a handler to the other dynamic control that could manage a "IamDoingSomething" flag in javascript.
Milan Mathew 16-Oct-12 16:49pm    
Your suggestion looks good. I'll need try this out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900