我想为我的网站创建图片幻灯片,例如特色网站下的此网站http://www.martynrussell.co.uk/default3.aspx?MenuID=1。
此图片的内容是动态的。有时整个内容会发生变化,或者某些时候位置属性会发生变化。
我能够让内容充满活力。
图片来自body onLoad,就像这样。
<body id="pageid1" onload="SetupFeaturedProperty(1,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-4.jpg']);SetupFeaturedProperty(2,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-4.jpg']);SetupFeaturedProperty(3,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-4.jpg']);SetupFeaturedProperty(4,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-4.jpg']);SetupFeaturedProperty(5,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-4.jpg']);">
现在我的问题是如何将此分配给主页上载。因为图像顺序正在动态变化。
昨天图像顺序是这样的。
<body id="pageid1" onload="SetupFeaturedProperty(1,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-4.jpg']);SetupFeaturedProperty(2,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/665-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/665-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/665-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/665-4.jpg']);SetupFeaturedProperty(3,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-4.jpg']);SetupFeaturedProperty(4,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-4.jpg']);SetupFeaturedProperty(5,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-4.jpg']);">
今天的图像顺序是这样的
<body id="pageid1" onload="SetupFeaturedProperty(1,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-4.jpg']);SetupFeaturedProperty(2,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-4.jpg']);SetupFeaturedProperty(3,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-4.jpg']);SetupFeaturedProperty(4,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-4.jpg']);SetupFeaturedProperty(5,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-4.jpg']);">
请建议我如何管理这个。如何在运行时分配值?
感谢。
答案 0 :(得分:1)
您的ContetPages将有不同的图像,您想要从MasterPage触发SetupFeaturedProperty功能?如果是这样,请尝试以下操作:
MasterPage.master
...
<head>
<asp:ContentPlaceHolder runat="server" id="Headers">
</asp:ContentPlaceHolder>
<script language=javascript>
function mp_onload()
{
if(window.body_onload != null)
window.body_onload();
}
</script>
</head>
<body onload="mp_onload();">
...
如果您的内容页面可能需要onload事件,那么您只需要在需要它的每个页面的Headers内容区域中创建一个名为body_onload
的函数。它会自动从MasterPage调用。
Default.aspx的
<asp:Content ID="Content2" ContentPlaceHolderID="Headers" Runat="Server">
<script language="javascript">
function body_onload()
{
SetupFeaturedProperty(1,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-4.jpg']);SetupFeaturedProperty(2,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-4.jpg']);SetupFeaturedProperty(3,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/38-4.jpg']);SetupFeaturedProperty(4,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/918-4.jpg']);SetupFeaturedProperty(5,['http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-1.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-2.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-3.jpg', 'http://www.brightlogic-estateagents.co.uk/MRUS/upload/1039-4.jpg']);
}
</script>
</asp:Content>
http://blog.thewightstuff.net/blog/2007/03/using-body-onload-with-aspnet-20.html
编辑:根据您对如何在代码隐藏中启动函数的评论(未经测试):
Dim allImageUrls As New List(Of String)(New String() {"http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-1.jpg", "http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-2.jpg", "http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-3.jpg", "http://www.brightlogic-estateagents.co.uk/MRUS/upload/1076-4.jpg", "http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-1.jpg", "http://www.brightlogic-estateagents.co.uk/MRUS/upload/122-2.jpg"})
If allImageUrls.Count <> 0 Then
Dim arrayBuilder As New System.Text.StringBuilder("[")
For Each imageUrl As String In allImageUrls
arrayBuilder.Append("'").Append(imageUrl).Append("',")
Next
arrayBuilder.Length -= 1 ' remove last comma '
arrayBuilder.Append("]")
Dim jsVarImgUrls As String = arrayBuilder.ToString
Page.ClientScript.RegisterArrayDeclaration("allImageURLs", jsVarImgUrls)
End If
然后,您可以从onload-function中轻松访问该数组,例如:
OnLoad = "SetupFeaturedProperty(1, allImageURLs);"