使用asp.net ClientScript时不会显示Facebox图像

时间:2011-03-25 13:06:28

标签: jquery asp.net facebox clientscript

我在ASP.net项目中使用FaceBox。当我从ASPX页面中的硬编码脚本块调用它时,它工作得很好:

<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>

然而,当我将代码移到代码后面以便我可以先执行一些服务器端代码时,框打开很好但不再显示图像(显示缺少的图像图标。单击图标确实有效。 )。这是我正在使用的代码:

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

我已经尝试更改参数的顺序(最后放“ajax”)。我已经尝试将事情分解成不同的功能。我已经尝试在硬编码的脚本块中设置loadingImage和closeImage。没有什么工作。

任何人都知道设置图像参数的正确语法吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

尝试

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

答案 1 :(得分:0)

感谢Firebug和一些反复试验,我想出了正确的语法和顺序:

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>")