Surya sasidhar Surya sasidhar - 1 year ago 86
ASP.NET (C#) Question

JavaScript for Datalist control in ASP.NET?

In Web application, I write JavaScript for mouseover and mouseout for a button to change the color. It is not working when button is in datalist control, it is working fine when button is outside of datalist control. This is my code, please help me.

<script type="text/javascript" >
function changeImage()
document.getElementById("btnView").style.background = "#AD1F13";

function changeImage1()
document.getElementById("btnView").style.background = "#005594";

<asp:DataList ID="dtlstMagazine" class='tableborder' runat ="server" Width ="100%"
<ItemTemplate >
<div style="text-align:left; " class="item-title" >
<asp:LinkButton Font-Underline ="false" ID="ltrlTitle" CommandName="Redirect" CommandArgument='<%# Eval("titleid") %>' Font-Bold ="true" Font-Size ="Medium" runat="server" Text ='<%# Eval("Title") %>'></asp:LinkButton>
<asp:Button ID="Btn_CR1" runat="server" Text="Continue Reading" CssClass='button3' onMouseOver="changeImage()" onMouseOut="changeImage1()" /> </ItemTemplate> </asp:DataList>

Answer Source

Actually you need a reference to buttons inside list to change their attribute. You can do this by changing your javascript method to:

function changeImage(obj) 
{   = "#AD1F13";

and your aspx to:

<asp:Button ID="Btn_CR1" runat="server" Text="Continue Reading"   CssClass='button3'  onMouseOver="changeImage(this)" onMouseOut="changeImage1(this)" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download