YZlat
asked on
JQuery works in plain html but not with ASP.NET
I have a button and div on my page. Div is not visible initially and I want to use JQuery to make it visible whenever the user clicks a button.
Below is my code that makes div invisible when the document loads and then, when the button is clicked, makes it visiable again. it works in plain html but not with ASP.NET page. On ASP.NET page, as soon as I click the button, the div appears for a second and disappears rigth away. Can someone help me fix my code?
<script type="text/javascript">
<!--
$(document).ready( function(){
$('#div1').css('display', 'none');
$('#btn1').click(function( ){
$('#div1').css('display', 'block');
});
});
//-->
</script>
1:
I tried using $('#div1').show() but it produces the same result
I also tried setting visibility to visible but to no avail
Below is my code that makes div invisible when the document loads and then, when the button is clicked, makes it visiable again. it works in plain html but not with ASP.NET page. On ASP.NET page, as soon as I click the button, the div appears for a second and disappears rigth away. Can someone help me fix my code?
<script type="text/javascript">
<!--
$(document).ready( function(){
$('#div1').css('display', 'none');
$('#btn1').click(function(
$('#div1').css('display', 'block');
});
});
//-->
</script>
1:
I tried using $('#div1').show() but it produces the same result
I also tried setting visibility to visible but to no avail
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dear Friend ,
If U want the button post back and as well as u need to make the div visible true then use the fallowing Code
In aspx Page
_____________
function fncVisible()
{
$('#div1').css('display', 'none');
$('#btn1').click(function( ){
$('#div1').css('display', 'block');
});
}
and in .cs Page
________________
Protected void button_Click(object sender,Eventargs e)
{
//If U have used Update Pannels in Aspx
ScriptManager.RegisterStar tupScript( this, this.GetType(), "VisiblePopup", "fncVisible();", true);
}
If U want the button post back and as well as u need to make the div visible true then use the fallowing Code
In aspx Page
_____________
function fncVisible()
{
$('#div1').css('display', 'none');
$('#btn1').click(function(
$('#div1').css('display', 'block');
});
}
and in .cs Page
________________
Protected void button_Click(object sender,Eventargs e)
{
//If U have used Update Pannels in Aspx
ScriptManager.RegisterStar
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked like a charm!
<input id="btn1" type="button" runat="server" value="Button 1" />