Asp.net标签不更新

时间:2014-07-29 17:34:11

标签: c# asp.net

我想在代码隐藏中的事件中更新标签文本。

母版页标签中的

声明为:

<asp:Content ID="WorklistBody" ContentPlaceHolderID="BodyHolder" runat="server">


    <asp:Label id ="lblOutput" runat="server" class="textStyle4" ForeColor="Red"></asp:Label>
    <asp:CustomValidator ID="CustomValidator1" ValidationGroup="SM" runat="server" ErrorMessage="CustomValidator" class="textStyle4" OnServerValidate="CustomValidatorServerValidate">
        </asp:CustomValidator>

// tables and other items goes on here......

我之前的开发人员使用以下内容来更新标签;

<script language="javascript" type="text/javascript">
        function ValidateComments() {
            var selOption = $('#<%= ddlActions.ClientID %> option:selected').val();
            if (selOption == 'C' || selOption == 'R' || selOption == 'U' || selOption == 'Q'|| selOption == 'P' || selOption == 'A') {
                var comment = $('#<%= txtComments.ClientID %>').val();
                comment = jQuery.trim(comment);
                if (comment == '') {
                    if (selOption == 'C') {
                        $('#<%= lblOutput.ClientID %>').text('Please enter comments before processing the transaction');
                    }
                    else if (selOption == 'R') {
                        $('#<%= lblOutput.ClientID %>').text('Please enter comments before cancelling the transaction');
                    }
                    else if (selOption == 'U' || selOption == 'Q' || selOption == 'P' || selOption == 'A') {
                        $('#<%= lblOutput.ClientID %>').text('Please enter comments before assigning the transaction');
                    }
                    window.scroll(0, 0); 
                    return false;
                }
            }
            return true;
        }
    </script>

但现在项目已经耗费,我需要检查很多逻辑。我想简单地从代码隐藏更新标签。

public void BtnDoneclick(object sender, EventArgs e)
{  
    //logic logic logic
    lblOutput.Text = @"Please enter comments before you Process this recommendation.";


}

为什么这不会更新标签?我该如何更新标签?

我是.net环境的新手

更新:Btn标记

<td align="right">
                                                             <div class="paddingStyle6 paddingStyle2">                                                                                
                                                            <asp:Button ID="btndone" runat="server" CausesValidation="true" ValidationGroup="SM"
                                                                        Text="Done" UseSubmitBehavior="True" Width="100px" OnClientClick="return ValidateComments()" OnClick="BtnDoneclick" />     

                                                            </div> 
                                                        </td>

1 个答案:

答案 0 :(得分:2)

如果该按钮位于更新面板中,则只更新该更新面板的内容。正在修改的标签是被忽略的页面的一部分。

尝试将按钮移出更新面板。