开发者

Facebox images don't show when using asp.net ClientScript

I'm using FaceBox in an ASP.net project. It works great when I call it from a hard-coded script block in the ASPX page like this:

<script type="text/javascript">

    jQuery(document).ready(function($) {
        $('a[rel*=facebox]').facebox({
            loadingImage: '../../CSS/FaceBox/Images/loading.gif',
            closeImage: '../../CSS/FaceBox/Images/closelabel.png'
        })
    });
</script>

However, when I move that code into code behind so that I can first execute some server side code, the box opens great but the images are no longer displayed (the missing image icon is displayed instead. Clicking the icon does work.). Here's the code I'm using:

Dim sbClientScript As System.Text.StringBuilder = New System.Text.StringBuilder()

sbClientScript.AppendLine("<script type='text/javascript'>")
sbClientScript.AppendLine("  jQuery.facebox({                                                   ")
sbClientScript.AppendLine("      ajax: 'EditQuestion.aspx',                                     ")
sbClientScript.AppendLine("      loadingImage: '../../CSS/FaceBox/Images/loading.gif',          ")
sbClientScript.AppendLine("      closeImage: '../../CSS/FaceBox/Images/closelabel.png'          ")
sbClientScript.AppendLine("    });                                                              ")
sbClientScript.AppendLine("</script>")

    If Not Page.ClientScript.IsStartupScriptRegistered("skFacebox") Then
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "skFacebox", sbClientScript.ToString())
    End If

I've tried changing the order of the parameters (putting "ajax" last). I've tried splitting things ou开发者_如何学运维t into different functions. I've tried setting the loadingImage and closeImage in a hard coded script block. Nothing is working.

Anyone know the correct syntax to set the image parameters?

Thanks!


Thanks to Firebug and some trial and error I came up with the correct syntax and ordering:

sbClientScript.AppendLine("jQuery.facebox.settings.loadingImage = '../../CSS/FaceBox/Images/loading.gif',")
sbClientScript.AppendLine("jQuery.facebox.settings.closeImage = '../../CSS/FaceBox/Images/closelabel.png'")
sbClientScript.AppendLine("<script type='text/javascript'>")
sbClientScript.AppendLine("  jQuery.facebox({")
sbClientScript.AppendLine("      ajax: 'EditQuestion.aspx'")
sbClientScript.AppendLine("    });")
sbClientScript.AppendLine("</script>")


Try

<%="~/CSS/FaceBox/Images/loading.gif"%> instead of '../../CSS/FaceBox/Images/closelabel.png' 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜