c# - Populate variables through code behind before the ASCX file is loaded -


i have code used show flash clock on website. getting source , time code behind , pass through flash swf json paramaters within ascx file, below:

<li class="clock">   <span id="divanalogclock">     <script type="application/json">       {settings:{id:'clock', src:'<%# analogclockurl %>', height:22, width:22, color:"#ffffff", allowscriptaccess:'samedomain', align:'middle', installmessage:'', flashvars:{time:"<%# sitetime %>", color:"#ffffff"}}}     </script>   </span> </li> 

which generate similar to:

<embed height="22" flashvars="time=<%# sitetime %>&amp;color=#ffffff"         pluginspage="http://www.adobe.com/go/getflashplayer"        src="<%# analogclockurl %>" type="application/x-shockwave-flash"        width="22" quality="high" wmode="transparent" allowscriptaccess="samedomain"         allowfullscreen="false" scale="exactfit" id="analogclock" color="#ffffff"        align="middle" name="analogclock"> 

the variables analogclockurl , sitetime being generated on page_load:

void page_load(object sender, eventargs e) {     loadclock(); }  private void loadclock() {     var flashlist = cmshelper.getflashlist(new list<string> { "clock" });     var flash = flashlist.singleordefault(f => f.key.equals("clock"));      if (flash != null)     {         analogclockurl = flash.flashurl;     }      sitetime = string.format("{0:hh}:{0:mm}:{0:ss}", timezoneinfo.converttimefromutc(datetime.utcnow, techsson.siteintegration.core.http.requestcontext.current.market.timezone)); } 

however, ascx being triggered first, hence fields being left empty , when page load kicked in, late (from debugging doing). should ensure variables populated first?

i open other suggestions solve issue, in case after not best way around it.

change <%# <%=

<%# used data binding have nothing being bound. could, if wanted to, add runat="server" embed markup , add analogclock.databind() in page_load event seems unnecessary in instance.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -