Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using the master page.and than inherit the content page from that master page.
and than i create a javascript function in content page.but it is not working properly .means it display image on button onclientclick .
the image is constantly show on page.
but the button click event dose,t working
The code is:

XML
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script language="javascript">
    function abc() {
        document.getElementById('ctl00_ContentPlaceHolder1_img').style.display = 'block';
    }
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="button1" runat="server" OnClientClick="abc(); return false;" Text="view image" />
     <asp:image id="img" runat="server" ImageURL="~/loadingAnimation.gif" style="display:none;" />
</asp:Content>



so Please help me out this.

Thanks in Advance.
Posted
Updated 6-Jun-11 20:07pm
v7
Comments
Ed Nutting 7-Jun-11 2:11am    
I would advise you put that javascript code in the Head section of your page, otherwise the function is likely to run onpageload, thus making your image always visible ;P
LittleBlackLui 7-Jun-11 9:30am    
pradeep_kr and RakeshMeena are right. Put an HTML button is the best option if you will only need to shoot javascript code.

Rakesh is right. An alternative with this one is to add a javascript code on the OnClientClick of your asp:Button tag. Take a look.
C++
<asp:Button ID="button1" runat="server" OnClientClick="abc(); return false;" Text="view image" />


[Update]
I did'nt know you had a server side event on your button, the code you posted is different. In this case, why wont you just set img.Visible = true on your button click event and img.Visible = false on your Page Load.
 
Share this answer
 
v2
Comments
RakeshMeena 7-Jun-11 1:31am    
My 5!!! I missed the point otherwise this is a better solution.
walterhevedeich 7-Jun-11 2:00am    
Thanks. Its just another solution incase OP is required to use ASP controls.
Rohit from Delhi 7-Jun-11 2:04am    
Sir
By using your solution
<asp:Button ID="button1" runat="server" OnClientClick="abc(); return false;" Text="view image" />
the button click event does,t working.so please help me
walterhevedeich 7-Jun-11 2:20am    
Please see my updated answer
Reason: When you click button postback happens and since you have declared the image as hidden in your markup, it becomes hidden again, hence the flickering.

Solution: Why don't you give html button a try: "<input id="button1" type="button" onclick="abc();" value="view image" />"
 
Share this answer
 
v3
use html button and put the abc() method on button click. it will not rendered you page.
 
Share this answer
 

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