0

我有一个简单的 asp.net 网页,其中包含 2 个RadioButton列表。提交表单时,会执行一些更复杂的代码,这需要一些时间(5-10 秒)才能执行。

我想ContentPlaceHolder在执行该代码之前简单地更改 2 之间的可见性。切换工作,但仅在执行复杂代码之后。

结果是页面冻结并在一段时间后发生变化。

我的aspx代码:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:PlaceHolder ID="requestpage" runat="server" Visible="true">
    <p>
    </p>
    <h1>
        Navigatie update</h1>
    <p>
    </p>
    <div style="text-align: left; width: 300px">
        <p>
            Kies een site</p>
    </div>
    <p>
        <asp:RadioButtonList ID="pubtargetid" runat="server">
        </asp:RadioButtonList>
    </p>
    <br />
    <br />
    <div style="text-align: left; width: 300px">
        <p>
            Kies een taal</p>
    </div>
    <p>
        <asp:RadioButtonList ID="chosenLanguage" runat="server">
        </asp:RadioButtonList>
    </p>
    <p style="color: red">
        <asp:Label ID="errorMessage" runat="server"> </asp:Label></p>
    <p>
        <asp:Button Text="Start update" OnClick="Submit" runat="server" />
    </p>
</asp:PlaceHolder>
<asp:PlaceHolder ID="responsepage" runat="server" Visible="False">
        <p>
        </p>
        <h1>
            Navigatie update</h1>
        <p>
            Navigatie wordt geüpdate</p>
        <p>
</asp:PlaceHolder>

我背后的代码:

using System;
using System.Web.UI.WebControls;
using System.Threading;
using Tridion.ContentManager.CommunicationManagement;
using Tridion.ContentManager;

namespace CustomPages
{
    public partial class Navigation : System.Web.UI.Page
    {
        private Session session;
        protected void Page_Load(object sender, EventArgs e)
        {
            session = new Session(Request.ServerVariables["LOGON_USER"]);
            Response.BufferOutput = true;
            Response.Flush();

            if (!Page.IsPostBack)
            {
                var targets = session.SystemManager.GetPublicationTargets();
                pubtargetid.Items.Clear();
                foreach (PublicationTarget t in targets)
                {
                    var radio = new ListItem(t.Title, t.Id);
                    pubtargetid.Items.Add(radio);
                }
                chosenLanguage.Items.Clear();
                var nl = new ListItem("NL", "NL");
                var fr = new ListItem("FR", "FR");
                chosenLanguage.Items.Add(nl);
                chosenLanguage.Items.Add(fr);
            }
        }

        public void Submit(object sender, EventArgs e) // --> when submitting the form
        {
            if (pubtargetid.SelectedIndex != -1 && chosenLanguage.SelectedIndex != -1)
            {
                requestpage.Visible = false;
                responsepage.Visible = true;
                Response.Flush();

                String pageId ="";

                String target = pubtargetid.SelectedItem.Value;
                String lang = chosenLanguage.SelectedItem.Value;

                //some code//

                var nav = new Automations.Navigation(session,page);
                nav.CheckPage(pageId, target);         //  --> complex piece of code
            }
            else
            {
                errorMessage.Text = "";
                if (pubtargetid.SelectedIndex == -1)
                {
                    errorMessage.Text += "Choose a publication target. \n";
                }
                if (chosenLanguage.SelectedIndex == -1)
                {
                    errorMessage.Text += "Choose a language.";
                }
            }
        }
    }
}

简而言之:我想让可见性在执行该复杂代码之前发生变化。

我尝试了不同的选择;就像试图刷新响应,但我没有成功,Response.BufferOutput = false还有一次= true,但仍然没有成功!

对此问题的任何帮助将不胜感激!

4

1 回答 1

1

你必须做两件事

将您的替换PlaceHolderPanel. (因为PlaceHolder不渲染到任何 HTML 标签,它只是按原样渲染它的内容,但我们必须获取一些父标签,以便我们可以隐藏显示客户端,所以使用Panel它作为渲染div)。

像这样做。

<asp:Panel runat="server" ID="Panel1" Style="display: none;">
     Place Holder one
</asp:Panel>
<asp:Panel runat="server" ID="Panel2">
     Place Holder two
</asp:Panel>
<asp:Button runat="server" ID="btn" OnClientClick="hideOne();" 
            OnClick="server_click" />

<script type="text/javascript" language="javascript">
function hideOne() {
    var one = document.getElementById('<%= Panel1.ClientID %>');
    one.style.display = 'block';
    var two = document.getElementById('<%= Panel2.ClientID %>');
    two.style.display = 'none';
}
</script>

protected void server_click(object sender, EventArgs e)
{
   Response.Write("Hid");
}

基本上,您应该在执行冗长的代码之前在客户端执行隐藏功能以获得所需的效果

于 2012-10-08T11:04:46.593 回答