Show/Hide panels in ASP.net C# after submitting form

家住魔仙堡 提交于 2019-12-11 09:07:48

问题


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.

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:

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.

Would I run the script to change the visibility at the try function when an email is sent, or right before the frmReset function?

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 true or false)


回答1:


According your comments, you will resolve your requirement in two steps.

1st, update your page load to avoid reverting visibility after you change it :

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 try method :

protected void Try_Click(object sender, EventArgs e)
{
    Panel1.Visible = false;
    Panel2.Visible = true;
    Panel3.Visible = false;
    Panel4.Visible = true;   
}


来源:https://stackoverflow.com/questions/11459914/show-hide-panels-in-asp-net-c-sharp-after-submitting-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!