Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a timing issue. Whats happening is Page_Load runs first in this case and THEN the Click event handler so effectively the control has been bound before the new entry is added. Thats why you're always one refresh behind. Id refactor your code like this so everything runs in the correct order! To understand the timing of event execution I strongly recommend <a href="http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx#lifecycle_events" rel="nofollow">reading this article on MSDN its AWESOME</a> and will really help you get the best from ASP.NET.</p> <p>Additionally <a href="http://msdn.microsoft.com/en-GB/library/75x4ha6s%28v=vs.100%29.aspx" rel="nofollow">reading this article on MSDN (Also awesome)</a> especially the section on ViewState will explain how the DropDown retains its details even when, in the modified code, you're onlly filling it when the page is NOT a postback and when the click event is fired. </p> <p>Hope this helps!</p> <pre><code>public void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; LoadOtherModulesUsed(); } private void LoadOtherModulesUsed() { if (this.GraphicName != null) { lbModules.Items.Clear(); var context = new XRefDataContext(); var q = context.GraphicModuleXRefs .Where(a =&gt; a.GraphicName.Contains(this.GraphicName)); foreach (GraphicModuleXRef gr in q) { lbModules.Items.Add(new ListItem(gr.Module.ToString())); } } } protected void btnModuleAdd_Click(object sender, EventArgs e) { var selectedModule = ddlModsList.SelectedItem.ToString(); var graphicName = this.GraphicName; var xr = new GraphicModuleXRef(); xr.GraphicName = graphicName; xr.Module = selectedModule; // Take drop down list selection and add it to GraphicModuleXRef table. var context = new XRefDataContext(); context.GraphicModuleXRefs.InsertOnSubmit(xr); context.SubmitChanges(); LoadOtherModulesUsed(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload