More in this section

Forums / Developing with Sitefinity / Pass server variable to javascript on Master Page?

Pass server variable to javascript on Master Page?

2 posts, 0 answered
  1. Jenn Bohm
    Jenn Bohm avatar
    17 posts
    Registered:
    19 Aug 2009
    28 Oct 2009
    Link to this post
    I want to embed a swfobject on the master page that accepts a flashvar. The value I need to pass into the flashvar must be generated in server code by querying the database. In a module, I was able to put the value in an asp:HiddenField, and use Response.Write to write a line of script declaring and assigning a javascript variable containing the ClientID of the hidden field, so the javascript in my module can get the value of the hidden field and pass it to the swfobject's flashvar. I used Response.Write because when I tried RegisterStartupScript, the line of script was showing up below the script that needed it, so it wasn't available when I needed it. Response.Write put it at the top of the page, and it worked.
    When I try to do this on the master page, whether I use RegisterStartupScript or Response.Write, whether I put it in Page_Load, Page_PreInit of the master page, the script doesn't show up in the page source at all.
    I want this flash object to appear at the top of every page in the site, so I thought it made sense to put it in the master page. Is there a way to accomplish this?

    *edit* - On further investigation, I've found that I can get this script early enough on the page to declare and assign the "clientID" variable before my script that uses it, but now my problem is that my script that reads the hidden field is executing before the hidden control itself gets rendered. So I no longer have a problem getting the clientID of the hidden field, I just don't have the hidden field in time to read it's value. My quest continues...
  2. Jenn Bohm
    Jenn Bohm avatar
    17 posts
    Registered:
    19 Aug 2009
    28 Oct 2009
    Link to this post
    Solved my own problem. Just had to move the script to a point below the asp:HiddenField...
    But maybe this will help someone else :)
2 posts, 0 answered