Definition of control that caused the reverse transmission

I have a page that returns messages in a drop-down list (using the AJAX update panel). Based on the drop-down list, the rest of the user interface on the page is dynamically generated. A dynamic user interface is drawn on the page load to get values ​​when the Submit button is clicked. The problem I am facing is that when changing the drop-down list, there are two reverse processes, one of which draws the original user interface and the one that draws the changed interface (thus creating inconsistency). How to deal with it. Is there a way to figure out which control caused the postback so that I can redraw the interface when postback happens due to pressing the select / submit button.

EDIT: missed an important question. The trigger for the update panel is the SelectionChanged drop-down list event. This causes an additional postback.

+4
source share
3 answers

You can check the postback and then do ..

 if (IsPostBack) { var targetID = Request.Form["__EVENTTARGET"]; } 

EDIT: you can get actual control by doing ..

 if (targetID != null && targetID != string.Empty) { var targetControl = this.Page.FindControl(targetID); } 
+12
source

Use separate server event handlers for your controls. For instance:

 public void DropDown_Changed(Object sender, EventArgs e) { // Drop down is changed. It the source of post back. } public void Button_Click(Object sender, EventArgs e) { // Button is the source of postback. } 
+1
source

Check if the drop-down list has AutoPostBack = "true", because this will cause the drop-down menu to be sent back even without clicking the submit button, so if you click the submit button, it will return back twice.

One way to find the control that caused the Request.Params.Get("__EVENTTARGET"); is to check Request.Params.Get("__EVENTTARGET");

+1
source

All Articles