Click here to Skip to main content
15,882,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello Friends,
in my webpage i set visibility of a div hidden and i want to show it on button click,so i am writing a jquery code for it. but some how it is not working.
My asp code is
ASP.NET
<asp:Button ID="btnGenerate" CssClass="button" runat="server" Text="Generate" OnClick="btnGenerate_Click" />
<div id="print" style="width: 80%; margin-removed 10%; margin-removed 20px;visibility:hidden;">                
                <input type="button" id="btnPrint" class="button" value="Print" onclick="printDiv('ReportDiv')"/>
</div>


and my jquery code is:

JavaScript
<script>
    $(document).ready(function () {
        $("#btnGenerate").click(function () {
            $("#print").css("visibility", "visible");
        });
    });
</script>

please help me to fix this issue. Thanks
Posted
Updated 5-Mar-14 0:46am
v2
Comments
Amalraj Ramesh 5-Mar-14 6:47am    
change the div id like btnPrint
or
$("#print").css("visibility", "visible");

Hi...
See this one!.
C#
<script>
$(document).ready(function () {
                $("#btnGenerate").click(function () {
                    $("#print").show();
                });
            });
</script>

XML
<asp:Button ID="btnGenerate" CssClass="button" runat="server" Text="Generate" OnClick="btnGenerate_Click" />
<div id="print" style="width: 80%; margin-removed 10%; margin-removed 20px;visibility:hidden;">
                <input type="button" id="btnPrint" class="button" value="Print" onclick="printDiv('ReportDiv')"/>
</div>

Thank u.
 
Share this answer
 
XML
Hi Amit,
   Please use  <input type="button" id="btnGenerate" class="button" value="Generate" /> instead of <asp:Button ID="btnGenerate" CssClass="button" runat="server" Text="Generate" OnClick="btnGenerate_Click" />

    In your code there is no any css or javascript error but do you know about Server Side Controls.There are mainly two types of controls First one is HTML control and second is ASP.NET controls.
    ASP.Net controls has the server side attributes that means when you use any server side control its getting postback event so that due to postback your javascript dosen't work.
 
Share this answer
 
Hi Friend,

You have two option to show the div.

1- Use onclientClick event & call you javascript function to show the div. And Use IsPostBack false in your page load event.

2- you make div as server control like runat="server". And make visible hide / show in your c# code.

3- Use return false like in below code but you can not call your server side event.

XML
<script>
$(document).ready(function () {
                $("#btnGenerate").click(function () {
                    $("#print").show();
return false;
                });
            });
</script>


Thanks
 
Share this answer
 
v2
try this

<script>
$(document).ready(function () {
$("#btnGenerate").click(function () {
$("#Print").css("visibility", "visible");
});
});
</script>
 
Share this answer
 
v2
What is the Purpose of your Function 'printDiv('ReportDiv')'? Is it use for Display that div.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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