OnClientClick in Repeater Control Flashing Javascript Image Swap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sully

    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_Item DataBound1">
    <HeaderTemplate >
    <ul>
    </HeaderTemplate>
    <ItemTemplate >
    <li>
    <asp:ImageButto n 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_ItemDa taBound1(object sender,
    RepeaterItemEve ntArgs e)
    {
    if (e.Item.ItemTyp e == ListItemType.It em ||
    e.Item.ItemType == ListItemType.Al ternatingItem)
    {
    {
    DataRowView drv = (DataRowView)e. Item.DataItem;
    string ID = drv["ID"].ToString();
    ImageButton myIBTN =
    ((ImageButton)e .Item.FindContr ol("ibtnSmall") );
    myIBTN.ImageUrl = "~/images/pages/customInstalls/
    SM/" + ID + ".jpg";
    myIBTN.OnClient Click = "javascript:rep laceImg('" +
    myIBTN.ImageUrl .Replace("SM", "LG").Replace(" ~", "..") + "');";
    imgLarge.ImageU rl = "~/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="JavaS cript">
    function replaceImg(path ) {
    var Image = document.getEle mentById('imgLa rge');
    Image.setAttrib ute("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
Working...