Click here to Skip to main content
14,240,732 members
Rate this:
Please Sign up or sign in to 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: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:

<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");
Rate this:
Please Sign up or sign in to vote.

Solution 3

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

<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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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.

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


Thanks
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

try this

<script>
$(document).ready(function () {
$("#btnGenerate").click(function () {
$("#Print").css("visibility", "visible");
});
});
</script>
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 5

What is the Purpose of your Function 'printDiv('ReportDiv')'? Is it use for Display that div.
   

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100