Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to hide panel on click of image button using javascript

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Mail.aspx.cs" Inherits="RecieptGeneration_Mail" %>

<!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">


</head>
<body>
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" runat="server">


<table>
<tr><td>To:</td><td><asp:TextBox ID="txtTo" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:ImageButton ID="ImageButton2" runat="server" Height="19px"
        ImageAlign="Right" ImageUrl="~/images/CloseIco.png" Width="21px" />
    </td></tr>
<tr><td>Subject:</td><td><asp:TextBox ID="txtSubject" runat="server"></asp:TextBox></td></tr>
<tr><td>Body:</td><td><asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine"></asp:TextBox></td></tr>
<tr><td></td><td><asp:FileUpload ID="FileUpload1" runat="server"/></td></tr>
<tr><td></td><td><table id="attachedfiles"></table></td></tr>
<tr><td>
    &nbsp;</td><td><asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click"/></td></tr>
</table>


    </asp:Panel>
    <p>
        &nbsp;</p>
    </form>
</body>
</html>
Posted

JavaScript
<script type="text/javascript">
    $(document).ready(function()
    {
        $('#<%= Imagebutton2.ClientID %>').click(function() { $('#Panel1').hide(); });

    });
</script></script>



Hoppe it helps.
Suggestion:-Its good to use
instead of panel.

Thanks
 
Share this answer
 
Comments
Mann Rai 19-Sep-13 4:57am    
it is not working
The Doer 19-Sep-13 5:04am    
What error are you getting?
Mann Rai 19-Sep-13 5:12am    
no error..page reloads nthing else happende
Mann Rai 19-Sep-13 7:25am    
plz give some suggestion ...
The Doer 19-Sep-13 22:19pm    
Have your installed JQuery to your website?
Hi Mann,

1. Use ClientIDMode property in ASP.Net to keep the ID of an element as specified during Design Time -
HTML
<asp:panel id="Panel1" runat="server" clientidmode="static">
<asp:imagebutton id="ImageButton2" clientidmode="static" runat="server" ....="">
</asp:imagebutton></asp:panel>


2. Write javascript to hide the panel as -
JavaScript
<script type="text/javascript">
    $(document).ready(function(){
        $('#Imagebutton2').click(function(e) { 
              $('#Panel1').hide();
              e.preventDefault();
        });

    });
</script>


3. If you are using .Net < 4.0 you can also use attribute selector to perform the same, but with some own limitations like no id should be ending with the same -
JavaScript
<script type="text/javascript">
    $(document).ready(function(){
        $('[id$="Imagebutton2"]').click(function(e) { 
              $('[id$="Panel1"]').hide();
              e.preventDefault();
        });

    });
</script>


I hope this helps
Thanks
 
Share this answer
 
v4

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