Reputation: 477
I have a asp.net user control, I added a image button and then in head I am using javascript/jquery to add a button event to it, so that it will show a message box on button click, now if I look into developers tools I can see CSS is loaded but when I click on image button all happens is a page refresh, now if I try to add alert("Message");
instead of my function it does work.
I would prefer to do it in front end.
<head id="head1">
<link href="/_LAYOUTS/1033/STYLES/abc/arts/galdtor.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/_layouts/1033/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("input[id$='btnSE']").click(function() {
$('body').append("<div id='M'><span id='text'></span><br/><div id='BPB' onclick='return BPB();'><a href='' onclick='return BPB();'></a></div></div>");
});
function BPB() {
$('#M').remove();
$('#EM').remove();
return false;
}
});
</script>
</head>
then in body I got this,
<div style="margin: 0px 0px 0px 5px; float: left;">
<asp:ImageButton ID="btnSE" runat="server" ImageUrl="/_LAYOUTS/1033/IMAGES/abc/arts/gtor/ow.png" />
</div>
Upvotes: 0
Views: 892
Reputation: 12693
This works for me.
<div style="margin: 0px 0px 0px 5px; float: left;">
<asp:ImageButton ID="btnSE" runat="server" OnClientClick="doWork(); return false;"
ImageUrl="/_LAYOUTS/1033/IMAGES/abc/arts/gtor/ow.png" />
</div>
<script type="text/javascript">
function doWork() {
$('body').prepend("<div id='M'><span id='text'></span><br/><div id='BPB' onclick='return BPB();'>
<a href='' onclick='return BPB();'></a>
</div></div>");
}
</script>
Upvotes: 1
Reputation: 431
<a href='' onclick='return BPB();'>
try
<a href='javascript:bool(BPB());'></a>
since you r not setting anything in the href the page will reload
Upvotes: 0