Member_2_1242703
asked on
Show/Hide ASP.NET controls with JQuery best practices
I'm currently hiding an ASP.NET panel on load using the following
Then I show it based on a dropdown change (based on the return of a webmethod), hide it again with a cancel button using...
I'm trying to figure out how to control showing and hiding on postback after the initial load? Obviously with my setup, the panel will be hidden on every post back. What is the best way to control showing and hiding a control?
<script type="text/javascript">
$(document).ready(function () {
$("#<%= pnlNewPlayer.ClientID %>").hide();
});
</script>
Then I show it based on a dropdown change (based on the return of a webmethod), hide it again with a cancel button using...
<script type="text/javascript">
function clearThis() {
$("#<%= pnlNewPlayer.ClientID %>").hide();
};
</script>
I'm trying to figure out how to control showing and hiding on postback after the initial load? Obviously with my setup, the panel will be hidden on every post back. What is the best way to control showing and hiding a control?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No way...that was too easy. Thanks!
FInal solution was I added this to my page load:
ClientScript.RegisterClien tScriptBlo ck(Me.GetT ype(), "isPostBack", String.Format("var isPostback = {0};", IsPostBack.ToString().ToLo wer()), True)
Then just changed my document ready script to:
<script type="text/javascript">
$(document).ready(function () {
if (isPostback) {
// Postback specific logic here
}
else {
$("#<%= pnlNewPlayer.ClientID %>").hide();
}
});
</script>
FInal solution was I added this to my page load:
ClientScript.RegisterClien
Then just changed my document ready script to:
<script type="text/javascript">
$(document).ready(function
if (isPostback) {
// Postback specific logic here
}
else {
$("#<%= pnlNewPlayer.ClientID %>").hide();
}
});
</script>
Open in new window
Complete Source :
http://www.aspsnippets.com/Articles/Show-Loading-Progress-Indicator-using-GIF-Image-when-UpdatePanel-is-updating-in-ASPNet.aspx
Open in new window
http://www.aspsnippets.com/Articles/Display-Loading-Animated-GIF-Image-Progress-Indicator-in-jQuery-AutComplete-Textbox.aspx
Open in new window
http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_ajaxcompleteDrop your queries for further assistance .
Thanks
Rajar