I have a form that is initially hidden through jQuery, and when I click the button, two radio buttons appear (also hidden initially through jQuery). When you click one switch, the user is redirected to another page (this works fine). When you click another switch, the "form" is again visible, through jQuery.
My problem arises when the field inside the "form" is checked on the server side during submission, and the page reloads with a validation error message, but the "form" is now hidden (according to the initial jQuery below).
How can I make the form visible in postback? (I already tried ASP panels and AJAX UpdatePanel to no avail.)
** This is my jQuery: **
// Reveal Radio Fields $(".btn-leavecomment, .txt-leavecomment").toggle(function(){ $("#commenttype").stop().animate({ down: "+=300" }, 3000) $("#commenttype").stop().slideDown("slow"); }, function(){ $("#commenttype").stop().animate({ down: "-=300" }, 1400) $("#commenttype").stop().slideUp("slow"); }); // Reveal Form on-click of one radio field in particular $(".reveal_ccform").toggle(function(){ $("#ccform_container").stop().animate({ down: "+=300" }, 4000) $("#ccform_container").stop().slideDown("slow:4000"); }, function(){ $("#ccform_container").stop().animate({ down: "-=300" }, 4000) $("#ccform_container").stop().slideUp("slow:4000"); });
A recently added JavaScript implementation (as suggested by Moar), this still doesn't work, any ideas? :(:
JavaScript:
<script type="text/javascript"> $(document).ready() { function isPostBack() { if (!document.getElementById('clientSideIsPostBack')) { return false; if (document.getElementById('clientSideIsPostBack').value == 'Y' ) return true; } // Reveal Comment Type $(".btn-leavecomment, .txt-leavecomment").toggle(function () { $("#commenttype").stop().animate({ down: "+=300" }, 3000) $("#commenttype").stop().slideDown("slow"); }, function () { $("#commenttype").stop().animate({ down: "-=300" }, 1400) $("#commenttype").stop().slideUp("slow"); }); // Reveal Sign Guestbook Form $(".reveal_ccform").toggle(function () { $("#ccform_container").stop().animate({ down: "+=300" }, 4000) $("#ccform_container").stop().slideDown("slow:4000"); }, function () { $("#ccform_container").stop().animate({ down: "-=300" }, 4000) $("#ccform_container").stop().slideUp("slow:4000"); }); // Hide 'Leave a Comment' button and 'Comment Type' div $('.reveal_ccform').click(function () { $(".btn-leavecomment").stop().fadeOut("slow:1500"), $('#commenttype').slideUp("slow:8000"); }); } } </script>
FROM#:
if (Page.IsPostBack) { Page.ClientScript.RegisterStartupScript(GetType(), "IsPostBack", script, true); //Second part of code will run if is postback = true ClientScriptManager cs = Page.ClientScript; Type csType = this.GetType(); cs.RegisterClientScriptBlock(csType, "openForms", "$(document).ready(openForms);", true); }