0

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

0

1 Answer 1

3

Change # to = to use a normal expression instead of a databound one.

Sign up to request clarification or add additional context in comments.

1 Comment

is not this enough? return HttpUtility.HtmlEncode(VirtualPathUtility.ToAbsolute(imgUrl.Path));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.