c# - Master Page label control not keeping value on postback -
i have ajax extender calendar control on master page. when fire selection changed event (below) pulls information , displays label control, when navigating different page in site loses information.
i have tried putting session variable on postback says values null.
the code
protected void calendar1_selectionchanged1(object sender, eventargs e) { var calendarparam = new sqlparameter("@g_datetime", sqldbtype.datetime); calendarparam.value = calendar1.selecteddate; var calendarparamnextday = new sqlparameter("@g_datetimeplusoneday", sqldbtype.datetime); calendarparamnextday.value = calendar1.selecteddate.adddays(1); using (sqlconnection sqlconn = new sqlconnection (system.configuration.configurationmanager.connectionstrings["islandersdb"].connectionstring)) { sqlcommand sqlcmd = new sqlcommand(); sqlcmd.parameters.add(calendarparam); sqlcmd.parameters.add(calendarparamnextday); sqlcmd.commandtype = commandtype.storedprocedure; sqlcmd.commandtext = "fixtures.getgamedetails"; sqlcmd.connection = sqlconn; sqlconn.open(); //sqldatareader sqldr = sqlcmd.executereader(); using(sqldataadapter sqlda = new sqldataadapter(sqlcmd)) { datatable dt = new datatable(); sqlda.fill(dt); foreach(datarow dr in dt.rows) { getopponenet go = new getopponenet(); go.gamedate = convert.todatetime(dr[0]); go.opponenet = dr[1].tostring(); go.location = dr[2].tostring(); string location = go.location ; string opponent = go.opponenet; datetime gamedate = go.gamedate; ; lblgamedate.text = gamedate.tostring(); lbllocation.text = location; lbloponenet.text = opponent; } } } }
any , massively appreciated
master page
<%@ master language="c#" autoeventwireup="true" codebehind="islanders.master.cs" inherits="cs_asp_islanders.islanders" %> <!doctype html public> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>peterborough islanders</title> <link href="_css/islanders-main.css" rel="stylesheet" type="text/css"> <link href="_css/stickyfooter.css" rel="stylesheet" type="text/css"> <asp:contentplaceholder id="head" runat="server"> </asp:contentplaceholder> <meta name="description" content="peterborough islanders nihl ice hockey club" /> <script type="text/javascript"> function printdiv(ticket_sale) { var printcontents = document.getelementbyid(ticket_sale).innerhtml; var originalcontents = document.body.innerhtml; document.body.innerhtml = printcontents; window.print(); document.body.innerhtml = originalcontents; } </script> </head> <body class="background"> <form id="form1" runat="server"> <div id="wrap"> <div id="main"> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <div class="main"> <div class="header"> <img src="_images/pagebasics/logo.fw.png" class="logo" alt="peterborough islanders" /> <img src="_images/pagebasics/billboard.fw.png" class="billboard" alt="next game" /> </div> <div class="body"> <div class="links"> <a href="default.aspx"><img src="_images/pagebasics/news.fw.png" border="0" height="46px" width="137px" alt="news"/></a> <a href="contact.aspx"><img src="_images/pagebasics/contact.fw.png" border="0" height="46px" width="137px" alt="contact us" class="headerlink"/></a> <a href="fixtures.aspx"><img src="_images/pagebasics/fixtures.fw.png" border="0" height="46px" width="137px" alt="fixtures , results" class="headerlink"/></a> <a href="gallery.aspx"><img src="_images/pagebasics/gallery.fw.png" border="0" height="46px" width="137px" alt="gallery" class="headerlink"/></a> <a href="roster.aspx"><img src="_images/pagebasics/roster.fw.png" border="0" height="46px" width="137px" alt="roster" class="headerlink"/></a> <a href="sponsorship.aspx"><img src="_images/pagebasics/sponsors.fw.png" border="0" height="46px" width="137px" alt="sponsors" class="headerlink"/></a> <a href="stats.aspx"><img src="_images/pagebasics/stats.fw.png" border="0" height="46px" width="137px" alt="stats" class="headerlink"/></a> </div> <div class="pageleft"> <asp:contentplaceholder id="body" runat="server"> </asp:contentplaceholder> <asp:contentplaceholder id="subbody" runat="server" > </asp:contentplaceholder> </div> <div class="pageright"> <div class="rightcontent" style="display:none"> <p>last game</p> <img src="_images/opponentlogo/islandersgameicon.fw.png" alt="home team" /> -v- <img alt="" src="_images/opponentlogo/cardiffdevilslogo.png" height="102" width ="124"/> <table width="295" border="1" cellspacing="0" cellpadding="0"> <tr> <td width="195px">teams</td> <td width="25px">1</td> <td width="25px">2</td> <td width="25px">3</td> <td width="25px">f</td> </tr> <tr> <td>peterborugh islanders</td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td>cardiff devils</td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </div> <div class="rightcontent"> <asp:updatepanel id="updatepanel1" runat="server" updatemode="always"> <contenttemplate> <asp:calendar id="calendar1" runat="server" backcolor="white" bordercolor="black" borderstyle="solid" cellspacing="1" font-names="verdana" font-size="9pt" forecolor="black" height="250px" nextprevformat="shortmonth" width="300px" ondayrender="calendar1_dayrender" onselectionchanged="calendar1_selectionchanged1"> <dayheaderstyle font-bold="true" font-size="8pt" forecolor="#333333" height="8pt" /> <daystyle backcolor="#cccccc" /> <nextprevstyle font-bold="true" font-size="8pt" forecolor="white" /> <othermonthdaystyle forecolor="#000000" /> <selecteddaystyle backcolor="#646473" forecolor="white" font-bold ="true" /> <titlestyle backcolor="#000000" borderstyle="solid" font-bold="true" font-size="12pt" forecolor="white" height="12pt" /> <todaydaystyle backcolor="#000000" forecolor="white" /> </asp:calendar> <%--</contenttemplate> </asp:updatepanel>--%> blue = home game <br /> orange = away game <br /><br /> <div class="calendargameinfo"> game date :<asp:label id="lblgamedate" runat="server" text=""></asp:label><br /> location :<asp:label id="lbllocation" runat="server" text=""></asp:label><br /> opponent :<asp:label id="lbloponenet" runat="server" text=""></asp:label> </div> </contenttemplate> </asp:updatepanel> </div> <div class="rightcontent"> <asp:contentplaceholder id="basketcounter" runat="server"> <asp:panel id="basket_panel" runat="server" visible="true" width="110%"> <div class="basket"> <div class="cart-count"> <span class="counter"> <img src="_images/stack.png" class="ion-bag" /> <%--<b id="order_counter" runat="server"> <asp:label id="lblcounter" runat="server" text=""></asp:label> </b>--%></span><span class="info-link"><a href="checkout.aspx">go basket <i class="ion-chevron-right"></i></a> </span> </div> </div> </asp:panel> </asp:contentplaceholder> </div> <img src="_images/pagebasics/facebook.png" class="facebook" alt="join on facebook" /> <p>proud working with</p> <img src="_images/pagebasics/phantoms.fw.png" alt="peterborough phantoms" /> </div> </div> </div> </div> </div> <div id="footer"> <div class="sponsors"> <img src="_images/pagebasics/linedivide.fw.png" alt="" /> <p>proudly supported by: </p> <br/> <img src="_images/sponsors/_logo-h87.fw.png" alt="" class="sponsorimage"/> <img src="_images/sponsors/officialclubnights.png" alt="offical club night out" class="sponsorimage" /> <br /> <img src="_images/sponsors/redlionbourne_logo.png" alt="the red lion - bourne" class="sponsorimage" /> <img src="_images/sponsors/planeticesmall.fw.png" alt="planet ice peterborough" class="sponsorimage" /> <img src="_images/sponsors/sinet.fw.png" alt="website hosted sinet development" /> </div> </div> </form> </body> </html> using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.data; using system.data.sql; using system.data.sqlclient; namespace cs_asp_islanders { public partial class islanders : system.web.ui.masterpage { protected void page_load(object sender, eventargs e) { } public datatable getdates() { datatable dt = new datatable(); sqlcommand sqlcmd = new sqlcommand(); sqlconnection sqlconn = new sqlconnection(system.configuration.configurationmanager.connectionstrings["islandersdb"].connectionstring); { sqlcmd.connection = sqlconn; try { sqlconn.open(); sqlcmd.commandtext = "select f.hometeam, f.awayteam, f.gamedateandtime, f.location fixtures.fixtures f"; sqldataadapter sqlda = new sqldataadapter(sqlcmd); sqlda.fill(dt); } catch (system.data.sqlclient.sqlexception ex) { string msg = "fetch error:"; msg += ex.message; throw new exception(msg); } { sqlconn.close(); } return dt; } } protected void calendar1_dayrender(object sender, dayrendereventargs e) { try { datatable dt = getdates(); datetime eventdate; string eventtype = string.empty; if (dt.rows.count > 0) { (int = 0; < dt.rows.count; i++) { //where columnfieldfordate , columnfieldforeventtype field names database eventdate = convert.todatetime(dt.rows[i]["gamedateandtime"]); eventtype = dt.rows[i]["location"].tostring(); if (e.day.date == eventdate.date) { if (eventtype == "peterborough") { e.cell.backcolor = system.drawing.color.skyblue; } else { e.cell.backcolor = system.drawing.color.orange; } } } } } catch (exception ex) { response.write("error: " + ex.message); } } protected void calendar1_selectionchanged1(object sender, eventargs e) { var calendarparam = new sqlparameter("@g_datetime", sqldbtype.datetime); calendarparam.value = calendar1.selecteddate; var calendarparamnextday = new sqlparameter("@g_datetimeplusoneday", sqldbtype.datetime); calendarparamnextday.value = calendar1.selecteddate.adddays(1); using (sqlconnection sqlconn = new sqlconnection (system.configuration.configurationmanager.connectionstrings["islandersdb"].connectionstring)) { sqlcommand sqlcmd = new sqlcommand(); sqlcmd.parameters.add(calendarparam); sqlcmd.parameters.add(calendarparamnextday); sqlcmd.commandtype = commandtype.storedprocedure; sqlcmd.commandtext = "fixtures.getgamedetails"; sqlcmd.connection = sqlconn; sqlconn.open(); //sqldatareader sqldr = sqlcmd.executereader(); using(sqldataadapter sqlda = new sqldataadapter(sqlcmd)) { datatable dt = new datatable(); sqlda.fill(dt); foreach(datarow dr in dt.rows) { getopponenet go = new getopponenet(); go.gamedate = convert.todatetime(dr[0]); go.opponenet = dr[1].tostring(); go.location = dr[2].tostring(); string location = go.location ; string opponent = go.opponenet; datetime gamedate = go.gamedate; ; lblgamedate.text = gamedate.tostring(); lbllocation.text = location; lbloponenet.text = opponent; } } } } //private void check_cart() //{ // //if (session["cart_counter"] == null) // //{ // // order_counter.innertext = "0"; // //} // //else // //{ // // basket_panel.visible = true; // // order_counter.innertext = convert.tostring(session["cart_counter"]); // //} //} } }
i found doing correctly using sessions, needed information in page_prerender
protected void page_prerender(object sender, eventargs e) { if(session["date"] != null) { string opponent = (string)session["opponent"]; string location = (string)session["location"]; datetime gamedate = (datetime)session["date"]; //datetime calendardate = (datetime)session["calendar"]; lbloponenet.text = opponent; lbllocation.text = location; lblgamedate.text = gamedate.tostring(); } } protected void page_load(object sender, eventargs e) { }
Comments
Post a Comment