Unclear solution at the end of the message
Using an asp.net page with C # codebehind, I successfully created and launched DropDownList.
What I would like to do is to capture a new value selected from the drop-down list (it is preferable to use postback for my code). Codebehind can then update other things on the page based on this newly selected dropdownlist value.
My first attempt was to use
<asp:DropDownList ID="myDDL" runat="server" AutoPostBack="true" OnSelectedIndexChanged="foo"></asp:DropDownList>
using c # method
public void foo(object sender, EventArgs e) { DropDownList ddl = sender as DropDownList; string myValue = ""; if (ddl != null) { myValue = ddl.SelectedValue;
This did not work. When the selected index was changed, it simply reloaded the page, but the IsPostBack flag was always false.
So, I sifted through SO and tried several different tactics. Most recently, I tried to register the onChange event on the client side in the code and disabled AutoPostBack.
on the ASP.Net page:
<asp:DropDownList ID="myDDL" runat="server" AutoPostBack="false"></asp:DropDownList>
in code:
myDDL.Attributes.Add("onChange", "doSomeStuff(this);"); // Done on databind.
I added client-side javascript to call the __doPostBack function page
<script language="javascript" type="text/javascript"> function doSomeStuff(ddl) { var ddlVals = document.getElementById(ddl.id); __doPostBack(ddlVals, ''); } </script>
This also failed, although I thought this was happening somewhere when I saw that javascript is executing correctly.
Looking at codebehind, it still doesn't work. When I set a breakpoint in Page_Load IsPostBack, that is a lie! But it must be a postback !? It was sent back using __doPostBack and (separately) automatically using AutoPostBack = "true"
So, I went deeper.
According to this MSDN article (http://msdn.microsoft.com/en-us/library/ms178141(v=VS.85).aspx) based on the results of loading the page, I do "Server Transfer", not required Postback (IsPostBack - false, PrePage, as expected, the same page that should be sent back, IsCallback - false, and IsCrossPagePosting - false).
What can happen for hyjack AutoPostBack and __doPostBack to make it look and act like a “server transfer”?
What can I install / check on the parent / page control to make sure it allows messages to be sent?
EDIT:
The load_page looks something like this:
private SpecialDataObject _someData; private string foobar; public void Page_Load(object sender, EventArgs e) {
With a breakpoint in //set some variables .IsPostBack page is always erroneous even after AutoPostBack.
EDIT 2:
The answer was in server transfer. In the remote control downloaded from the main page, the URL is checked and redirected before it gets to the page, which actually denies my postback. I have not seen this before because I added breakpoints only on the landing page.