background
i have table of items user can edit. can navigate through fields arrow keys, , information in current row saved when move new one. project requires notification displayed user when row saved, , boss requires me through bootstrap alerts.
one alert needs created each successful save, , if user saves multiple rows in short time should stack inside of panel. because number of alerts unknown, i'm dynamically adding them page code-behind. each alert made of panel , label, being added larger panel holds alerts. part i've got figured out -- alerts show when they're supposed to, , in correct numbers.
the problem each alert supposed show on screen limited amount of time. somewhere between 2 , 5 seconds, determined boss @ later date. idea start timer 2 seconds each time alert created, , remove first alert panel when timer finished. because no 2 timers created @ same time, should theoretically remove each alert 2 seconds after appears, stopping once last alert gone. unfortunately me, isn't how it's working.
instead, 'index out of bounds' exception, indicating alert i'm trying remove doesn't exist. exist -- can see on screen. i'm not sure what's going wrong.
code
creation of alerts
this code inside of page_load, alerts still visible on postback.
if (session["success"] != null) { int test = convert.toint32(session["success"]); for(int = 1; <= test; a++) { panel alert = new panel(); alert.cssclass = "alert alert-success"; alert.id = "dynamicalert" + a; alert.attributes["role"] = "alert"; label inneralert = new label(); inneralert.id = "dynamicalertinner" + a; inneralert.text = "<strong>success!</strong> row saved."; alert.controls.add(inneralert); alertsupdate.contenttemplatecontainer.findcontrol("pnlalerts").controls.add(alert); system.timers.timer time = new system.timers.timer(2000); time.elapsed += removealert; time.start(); } }
deletion of alerts
the removealert method intended remove alert @ index 0 panel contained within update panel.
private void removealert(object source, system.timers.elapsedeventargs e) { panel pnl = (panel)alertsupdate.contenttemplatecontainer.findcontrol("pnlalerts"); if(pnl != null && pnl.controls.count > 0) { pnl.controls.removeat(0); } }
Comments
Post a Comment