提交表单后在 ASP.net C# 中显示/隐藏面板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11459914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show/Hide panels in ASP.net C# after submitting form
提问by jzacharia
So in the process of combining my default.aspx form page with the confirm.aspx confirmation page, I had to create panels and show/hide them at the initial loading of the page.
因此,在将我的 default.aspx 表单页面与 confirm.aspx 确认页面结合的过程中,我必须创建面板并在页面初始加载时显示/隐藏它们。
The form is a comment/complaint form, so users will submit their info, and an e-mail is generated and sent to a web master.
该表单是一个评论/投诉表单,因此用户将提交他们的信息,并生成一封电子邮件并发送给网站管理员。
I have 4 panels: Panels 1 + 3 show by default and are set to visible early in the script like so:
我有 4 个面板:面板 1 + 3 默认显示,并在脚本的早期设置为可见,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = true;
Panel4.Visible = false;
}
Basically, I want panels 1+3 to become hidden, and 2 + 4 to become visible once the user submits the form and no errors are found within the forum.
基本上,我希望面板 1+3 变为隐藏状态,而 2 + 4 则在用户提交表单且论坛中未发现错误后变为可见。
Would I run the script to change the visibility at the tryfunction when an email is sent, or right before the frmResetfunction?
我会在try发送电子邮件时还是在frmReset函数之前运行脚本来更改函数的可见性?
Also, is there a specific function I need that will switch the panels visibility AFTER submitting the form with no errors found? (Other than changing visibility to trueor false)
另外,是否有我需要的特定功能可以在提交表单后切换面板可见性而没有发现错误?(除了将可见性更改为true或false)
采纳答案by Steve B
According your comments, you will resolve your requirement in two steps.
根据您的意见,您将分两步解决您的要求。
1st, update your page load to avoid reverting visibility after you change it :
1st,更新您的页面加载以避免在更改后恢复可见性:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = true;
Panel4.Visible = false;
}
}
2nd, you have to change the visibility on the trymethod :
第二,你必须改变try方法的可见性:
protected void Try_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
Panel4.Visible = true;
}

