Search code examples
c#asp.netsharepointweb-parts

How to launch DropDownList SelectedIndexChanged event only if clicked on spicified button?


So. I'm generating a lot of DropDownLists on page. Page has a 2 Views, first has this DDLs that can be changed, second view is doing some other things and user can change this views.

Because DDLs are generated I'm rebuilding them in protected override void OnInit in order to be able see changes in them by user (autopostback on DDLs are disabled).

So now about problem.

Everything is working, but not in totally correct way. If some DDLs are changed and page is starting to reload because of postback (caused by any button click, in this case by button that changes views) SelectedIndexChangedevent is shooting and doing it's things.

Is there a way to make SelectedIndexChanged event shoot only if user presses some particular "save" button and not shooting after presses on any other buttons (that causes postback)?


Solution

  • Add if(Page.IsPostback) return; to your SelectedIndexChanged event handler, and call your event handler directly from the button's OnClick method.

    The tricky part is you have to make your event handler function without using EventArgs.