简体   繁体   English

Asp .Net UpdatePanel不能正常工作

[英]Asp .Net UpdatePanel not working

I am using an UpdatePanel to show some controls that are normally hidden. 我使用UpdatePanel来显示一些通常隐藏的控件。

This is the code that I am using: 这是我正在使用的代码:

<asp:LinkButton runat="server" class="btn blue h27" CausesValidation="false" ID="lnkSuggestArticle"
                OnClick="lnkSuggestArticle_Click"><%=Supplier.GetResource("Answers_lnkSuggestArticle")%> <i class="icon icon_next_02 fr"></i></asp:LinkButton>
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <div class="infoRequest" id="divSuggestion" runat="server" visible="false">
                        <br class="clearfix" />
                        <h3>
                            Please provide the information you want to see on our support site:</h3>
                        <br class="clearfix" />
                        <asp:TextBox runat="server" ID="txtSuggestArticle" Rows="10" ValidationGroup="s" Width="100%"
                            TextMode="MultiLine"></asp:TextBox>
                        <div id="divEmailAddress" runat="server" visible="false">
                            <br />
                            <h3>
                                Please enter your email address</h3>
                            <asp:TextBox runat="server" ID="txtEmailAddress" Rows="1" ValidationGroup="s" CssClass="suggestionEmail"
                                TextMode="SingleLine"></asp:TextBox>
                            <br />
                        </div>
                        <br />
                        <asp:Label runat="server" ID="lblSugestedArticleError" ForeColor="Red" Visible="false"></asp:Label>
                        <asp:Label runat="server" ID="lblMessage" ForeColor="Red"></asp:Label>
                        <br />
                        <asp:LinkButton ID="btnSaveSuggestion" ValidationGroup="s" runat="server" OnClick="btnSaveSuggestion_Click"
                            CssClass="btn blue fr"><%=Supplier.GetResource("createticket_btnSuggest")%> <i class="icon icon_next_02 fr"></i></asp:LinkButton>
                        <%--<input type="submit" value="Suggest" class="btnSuggest" />--%>
                        <br />
                        <br />
                        <p id="notice" runat="server">
                            <asp:Label runat="server" ID="lblSuggestionNote" /></p>
                    </div>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="lnkSuggestArticle" />
                </Triggers>
            </asp:UpdatePanel>

When the user clicks the lnkSuggestArticle button I execute the following code: 当用户单击lnkSuggestArticle按钮时,我执行以下代码:

protected void lnkSuggestArticle_Click(object sender, EventArgs e)
{
    divSuggestion.Visible = true;
    if ((WFSS.DataAccess.Entities.Customer)Session["__currentCustomer"] == null)
    {
        divEmailAddress.Visible = true;
    }
}

But it doesn't update the page. 但它不会更新页面。 The div still stays hidden when the user clicks the suggest button. 当用户点击建议按钮时, div仍然隐藏。

It turns out that there was a bug in Visual Studio. 事实证明,Visual Studio中存在一个错误。 I had commented a piece of code in the aspx file. 我在aspx文件中评论了一段代码。 Turns out even though it appeared to be commented the code still executed which caused another update panel to be added which gave me an error in javascript. 事实证明,即使它似乎被评论仍然执行的代码导致另一个更新面板被添加,这给了我一个javascript错误。

   protected void lnkSuggestArticle_Click(object sender, EventArgs e)
{
    divSuggestion.Visible = true;
    if (Session["__currentCustomer"] == null)
    {
        divEmailAddress.Visible = true;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM