Click here to Skip to main content
14,304,598 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone ,
Now I'm creating a website in ASP.Net with framework 4.0 . I have to slide down a div when I click a asp:Button , i wrote script as

<script type="text/javascript">
    $(document).ready(function () {
        $('#<%= Button1.ClientID %>').click(function () {
            $('div#content').show('slow');
        }
        );
    });
   </script>

and button is created as
<asp:Button id="Button1" runat="server" text="Button" style ="width :auto" />

and the div is
<div id ="content" style ="display :none "  > this is a div</div>

The problem is after clicking the button the div shows and hides automatically. But when i use the button as
<input type ="button"  id="Button1"  runat="server" text="Button" style ="width :auto" />


then it works properly ... I dont understand what is happening .. Please solve my problem


Thank you all
Posted
Updated 9-Aug-12 21:34pm
v3
Comments
Sandeep Mewara 10-Aug-12 1:09am
   
What do you see in View Source for first case? I believe the HTML equivalent will be the same.
Geo Jackson 10-Aug-12 1:44am
   
I need to write some code in CS for the Button1
Abdul Quader Mamun 10-Aug-12 5:15am
   
where is you complete code?
Volynsky Alex 10-Aug-12 5:52am
   
Good question!
Rate this:
Please Sign up or sign in to vote.

Solution 1

This behavior is correct.

When you use asp.net button it makes postback so your div get hided though you dont add onclick event(server side).
But when you use html button & add attribute runat="server" it will not make postback.

So you should use html button or if you want to add asp.net button then add onclineclick like
<asp:button id="Button1" runat="server" text="Button" onclientclick="return false;" style="width :auto"  />


Add debug point add page load you will get idea.
   
v2
Comments
Geo Jackson 10-Aug-12 5:25am
   
Thank you so much . It Worked
Geo Jackson 10-Aug-12 5:25am
   
I got a new problem. After adding a OnClientClick the code in csharp for the button doesnt execute
Volynsky Alex 10-Aug-12 5:48am
   
Nice answer
pradiprenushe 10-Aug-12 5:56am
   
Thanks Volynsky Alex
Rate this:
Please Sign up or sign in to vote.

Solution 2

hiih dude

if you observe your page source you will see that

<asp:button id="Button1" runat="server" text="Button" style="width :auto" xmlns:asp="#unknown">

is Equivalent to

<input type="submit" name="Button1" value="Button" id="Button1" />

which is different than

<input type ="button" id="Button1" runat="server" text="Button" style ="width :auto" />
   
Comments
Geo Jackson 10-Aug-12 6:25am
   
is it possible to write csharp code for the button <input type="submit" name="Button1" value="Button" id="Button1" />
Ganesh Nikam 10-Aug-12 7:47am
   
yes when you added id and runat attribute it will be server side control
Geo Jackson 10-Aug-12 8:05am
   
ok then when i click which code executes first
Ganesh Nikam 10-Aug-12 8:37am
   
obvious client side
Rate this:
Please Sign up or sign in to vote.

Solution 3

see the below sigle line code for your que..

<div id="content"> this is a div</div>

<input type ="button"  id="Button1"  runat="server" text="Button" onclick="  $('#content').slideDown(100);" />
   
Comments
Geo Jackson 10-Aug-12 6:15am
   
thanks but i need a asp:Button

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100