Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
<br />
Account += @"<div class='header_readcount_float_row_img2' onclick=""DisplayMessage('Frm_Phonebook.aspx','fffffff','Frm_Phonebook.aspx')"" ><a  href=""javascript:void(0)"" > <img  src='images/delete.bmp'  /> </a>";<br />



i want to make an alert onclick event of that image???????
thanks
Posted

Below is the javascript code found in the head tag:
<script type="text/javascript">
    
        function HideDiv() 
        { 
            if (document.getElementById) 
            { // DOM3 = IE5, NS6 
                document.getElementById('myDiv').style.visibility = 'hidden'; 
            } 
            else 
            { 
                if (document.layers) 
                { // Netscape 4 
                    document.hideShow.visibility = 'hidden'; 
                } 
                else 
                { // IE 4 
                    document.all.hideShow.style.visibility = 'hidden'; 
                } 
            } 
        }
        
        function ShowDiv() 
        { 
            if (document.getElementById) 
            { // DOM3 = IE5, NS6 
                document.getElementById('myDiv').style.visibility = 'visible'; 
            } 
            else 
            { 
                if (document.layers) 
                { // Netscape 4 
                    document.hideShow.visibility = 'visible'; 
                } 
                else 
                { // IE 4 
                    document.all.hideShow.style.visibility = 'visible'; 
                } 
            }
        }
    
</script>


Below is the html code found in the body tag:
XML
<img src="C:\myPic.jpg" onclick="ShowDiv()" width="100px" height="100px" />
<div id="myDiv" style="visibility:hidden; background-color:Blue; z-index:100" >
<asp:Label ID="lblQuestion" runat="server" Text="Do you want to delete image?"></asp:Label>
<asp:Button ID="btnYes" runat="server" Text="Yes" OnClick="btnYes_Click" />
<asp:Button ID="btnNo" runat="server" Text="No" OnClientClick="HideDiv()" />
</div>



Below is the C# code:
C#
protected void btnYes_Click(object sender, EventArgs e)
{
     System.IO.File.Delete("C:\\myPic.jpg");
}
 
Share this answer
 
Comments
moon2011 8-Mar-11 16:21pm    
thanks for your help, but i tried it and an ececption appear in the line
document.getElementById('myDiv').style.visibility = 'visible';
"Microsoft JScript runtime error: Object required"
Ryan Zahra 10-Mar-11 3:17am    
you must replace 'myDiv' with the id of the div that you are using
<img src='images/delete.bmp' onclick="alert('This is an alert box!!')" />
 
Share this answer
 
Comments
moon2011 8-Mar-11 8:35am    
i want it as aconfirm alert????
Ryan Zahra 8-Mar-11 8:37am    
This should help you more:
http://www.tizag.com/javascriptT/javascriptconfirm.php
moon2011 8-Mar-11 8:40am    
thanks alot, but i need when he answer go to delete function, how can i do that????????
Ryan Zahra 8-Mar-11 8:52am    
You should have asked all that from the start...

Anyway, I myself, use the following method:
-> When the client clicks on the image, I would show a hidden div.
-> This div contains the required question and two buttons (Yes/No)
-> If the user clicks 'No', I would hide the div.
-> If the user clicks 'Yes' I would call the delete function.
moon2011 8-Mar-11 9:00am    
i am sorry for not telling the full question, but can you tell me how to make that??
how to tell an image in the run time to appear adiv ????

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900