471,337 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

OnClientClick in Repeater Control Flashing Javascript Image Swap

Hi Guys,

I have this about 98% done and I cannot get it work properly. I have a
Repeater bound to a MySQL DataSource, inside the Repeater I have an
ImageButton, outside the repeater I have a Image, code is below:

<asp:Image ID="imgLarge" Name="imgLarge" runat="server"
AlternateText="Large Custom Image" Height="300" Width="400" />
<asp:Repeater ID="rptSmall" runat="server"
OnItemDataBound="rptSmall_ItemDataBound1">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:ImageButton ID="ibtnSmall" runat="server"
Height="79" Width="105" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>

The OnItemDataBound command is setting the ImageURL and OnClientClick
command:
protected void rptSmall_ItemDataBound1(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
{
DataRowView drv = (DataRowView)e.Item.DataItem;
string ID = drv["ID"].ToString();
ImageButton myIBTN =
((ImageButton)e.Item.FindControl("ibtnSmall"));
myIBTN.ImageUrl = "~/images/pages/customInstalls/
SM/" + ID + ".jpg";
myIBTN.OnClientClick = "javascript:replaceImg('" +
myIBTN.ImageUrl.Replace("SM", "LG").Replace("~", "..") + "');";
imgLarge.ImageUrl = "~/images/pages/customInstalls/
LG/" + ID + ".jpg";
}
}
}

When the ImageButton is clicked it should change the large image
(imgLarge) to the small image being clicked with the javascript below:
<script type="text/javascript" language="JavaScript">
function replaceImg(path) {
var Image = document.getElementById('imgLarge');
Image.setAttribute("src", path);
}
</script>

For some reason, the large image (imgLarge) is only flickering to the
selected image and then going back to the default URL. if (!
Page.IsPostBack) is at the top of the Page_Load. Any ideas would
really be helpful.

Thanks in Advance,
Sully
Jun 27 '08 #1
0 1896

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matthew Law | last post: by
2 posts views Thread by No One | last post: by
4 posts views Thread by nicholas | last post: by
1 post views Thread by Jeff | last post: by
5 posts views Thread by =?Utf-8?B?Y3lydXM=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.