I have a form which is initially hidden via jQuery, and on click of a button two radio buttons appear (also hidden initially via jQuery). On click of one radio button, the user is redirected to another page (this works fine). On click of the other radio button "the form" is made visible again, via jQuery.
My problem comes when a field within 'the form' is validated server-side on submit, and the page is reloaded with the validation error message visible BUT the 'form' is now hidden (as per the initial jQuery below).
How can I make the form visible on postback? (I have already tried ASP Panels & 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");
});
Newly Added JavaScript implementation (as per Moar's suggestion) this is still not working, 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>
C#:
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);
}