【发布时间】:2011-09-18 05:53:05
【问题描述】:
我有一个最初通过 jQuery 隐藏的表单,单击按钮时会出现两个单选按钮(最初也通过 jQuery 隐藏)。单击一个单选按钮后,用户将被重定向到另一个页面(这很好用)。单击另一个单选按钮时,“表单”通过 jQuery 再次可见。
我的问题是当“表单”中的字段在提交时在服务器端进行验证,并且页面重新加载时验证错误消息可见但“表单”现在已隐藏(根据下面的初始 jQuery)。
如何使表单在回发时可见? (我已经尝试过 ASP Panels & AJAX UpdatePanel 无济于事。)
** 这是我的 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");
});
新添加的 JavaScript 实现(根据 Moar 的建议)这仍然不起作用,有什么想法吗? :( :
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);
}
【问题讨论】: