I am trying to create an add to ‘favourites’button. When the user clicks this button the image has to be changed ( in js). After that I would like to do a postback the asp.net page? how can I make this work? sofar i got:
aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
function ChangeFavStar() {
if ($("#btnAddToFavs").attr('src') == 'starempty.jpg') {
$("#btnAddToFavs").attr('src') = 'staradded.jpg';
}
else {
$("#btnAddToFavs").attr('src') = 'starempty.jpg';
}
return true;
}
});
</script>
<style type="text/css">
#btnAddToFavs {
height: 79px;
width: 121px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID=btnAddToFavs runat=server
OnClientClick="ChangeFavStar();" ImageUrl="~/starempty.jpg"
Height="74px" Width="109px" />
</div>
</form>
</body>
</html>
cs behindcode
protected void btnAddToFavs_Click(object sender, ImageClickEventArgs e)
{
//do stuff
}
You may invoke
JavaScriptfunction but changes on button wont be persisted because of postback. You have to changeImageUrlproperty via C# code.Markup: