Reputation: 9621
I have this c# user control class:
public partial class UserControls_JsTop : System.Web.UI.UserControl
{
public static string sidebarBannerUrl = getSideBarBannerImgUrl();
protected void Page_Load(object sender, EventArgs e)
{
}
public static string getSideBarBannerImgUrl(){
DataClassesDataContext db = new DataClassesDataContext();
var imgUrl = (from b in db.Banners
where b.Position.Equals(EBannersPosition.siderbar.ToString())
select b).FirstOrDefault();
if (imgUrl != null)
return imgUrl.Path;
return String.Empty;
}
}
I try to acces the static var in a js script:
load it here:
<script type="text/javascript">
var categoryParam = '<%# CQueryStringParameters.CATEGORY %>';
var subcategory1Param = '<%# CQueryStringParameters.SUBCATEGORY1_ID %>';
var subcategory2Param = '<%# CQueryStringParameters.SUBCATEGORY2_ID %>';
var imgUrl = '<%# UserControls_JsTop.sidebarBannerUrl %>';
</script>
and use it here (imgUrl):
<script type="text/javascript" language="javascript">
$(function () {
$(document.body).sidebar({
size: "30px", // can be anything in pixels
length: "270px", // can be anything in pixels
margin: "300px", // can be anything in pixels
position: "left", // left / bottom / right / top
fadding: "0.8", // 0.1 to 1.0
img: imgUrl,
openURL: "www.twitter.com/amitspatil"
});
});
</script>
I do not understand why it is empty. Please trust me that there is a record in DB with that condition.
I think there is some js problem when loading the var...
Do you know where?
thanks
Upvotes: 0
Views: 101
Reputation: 887275
Change #
to =
to use a normal expression instead of a databound one.
Upvotes: 3