0

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>
0

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

You must prevent the postback by returning false
Only thing I would say, your a life saver, working now like a charm
0
<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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.