Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net my list is disappearing on postback - can't find what I'm missing?
    primarykey
    data
    text
    <p>This is probably an easy one, but I can't figure it out. argh...</p> <p>C# asp.net application with a custom user control. My custom control is a simple list of images wrapped in a link to be used as a navigation tool for the parent page.</p> <p>When I click a link, it does a postback: my click event does not seem to fire, and when the page reloads, the list of images disappears.</p> <p>I have <code>EnableViewState="true"</code> in both the parent page and the custom control. It is my understanding that this would be enough to preserve my list of options? If I reload the list each time and rebind my event handler, I would think then that the event would be lost, correct?</p> <p>Here is (abbreviated code) where I add the controls to my panel. </p> <pre><code> public void LoadMediaOptions() { loop through a datareader { LinkButton b = new LinkButton(); b.Click += new EventHandler(navOption_Click); b.Attributes.Add("mediaID", mediaID.ToString()); HtmlImage i = new HtmlImage(); i.Src = strThumbLink; i.Width = 120; i.Height = 90; b.Controls.Add(i); _loadedMediaHtml.Add(b); panMediaOptions.Controls.Add(b); } } </code></pre> <p>This method is currently only being called once in the parent page in the Page_Load method:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) uxMediaNav.LoadMediaOptions(); } catch (Exception ex) { throw ex; } } </code></pre> <p>After the page posts-back, there are no media options loaded for me. My understanding of the EnableViewState is that it would preserve the elements I have loaded dynamically, but this is not the case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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