Postback not maintaining selected values
<p>I have a page with several dynamically generated DropDownLists. The DDs load and display the correct values on page load. However, when I try to retrieve the values at post back, the DDs all seem to be maintaining the values they had at page load.</p>

<p>All are created in Page_Load;
No test for IsPostBack;
Processing is handled in code below:</p>

<pre><code>void btnSubmit_Click(object sender, EventArgs e)

{

System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("\\") + "\\Logs\\Permissions.log",false);

string szMask = hMask.Value.ToString();
sw.WriteLine("\t\t\t\t\t\t\t" + szMask);

foreach (Control c in Page.Controls)
    LoopControls(c, szMask, sw);
sw.Close();
}

private void LoopControls(Control Page, string szMask, System.IO.StreamWriter sw)
{

foreach (Control c in Page.Controls)
{
    if (c is DropDownList)
    {
        string szId = c.ID;
        if (szId.StartsWith("ddlPerm"))
        {
            string[] szSplit = szId.Split(':');
            int iMaskPosition = Convert.ToInt32(szSplit[1].ToString());
            int iSecurityPermissionID = Convert.ToInt32(szSplit[2].ToString());
            DropDownList dd = (DropDownList)c;
            string szPermission = dd.SelectedValue.ToString();
            if (szMask.Substring(iMaskPosition, 1) != szPermission)
            {
                sw.WriteLine("NE");
                if (iMaskPosition == 0)
                    szMask = szPermission + szMask.Substring(1);
                else
                    szMask = szMask.Substring(0, iMaskPosition) + szPermission + szMask.Substring(iMaskPosition);
            }
            sw.WriteLine(szId + "\t\t" + iMaskPosition.ToString() + "\t" + iSecurityPermissionID.ToString() + "\t" + szPermission + "\t\t" + szMask);
        }
    }
    else
    {
        if (c.Controls.Count &gt; 0)
        {
            LoopControls(c, szMask, sw);
        }
    }
}
}
</code></pre>

<p>This is really bugging me. Any help would be greatly appreciated.</p>

<p>Thanks,
jb</p>
