ASP.NET - 从代码后面评估按钮值

时间:2016-01-26 09:42:23

标签: javascript c# jquery asp.net

我有一个asp按钮,当用户点击它时调用C#方法:

<asp:Button id="btnReport2" name="btnReport2"  runat="server" Text="Show Report" ToolTip="Report" OnClick="btnReport2_Click"/>

调用以下方法:

 protected void btnReport2_Click(object sender, EventArgs e)
        {
            if (btnReport2.Text == "Show Report")
            {
                GetReport();

            }

            ClientScript.RegisterStartupScript(Page.GetType(), "ShowReport", "ShowReport()", true);
    }

正如您所看到的,在方法结束时,我调用了一个jQuery脚本:

function ShowReport() {
            debugger;
            if ($('#btnReport2').val() == 'Show Report') {
                $('#btnReport2').val('Hide Report');
                $('#spPrint').attr('style', 'display:inline');
                $('#btnDeleteAll2').animate({ width: ['toggle', 'swing'], heigth: ['toggle', 'swing'], opacity: 'toggle' }, 500, "swing");
                $('#divReport').animate({ width: ['toggle', 'swing'], heigth: ['toggle', 'swing'], opacity: 'toggle' }, 500, "swing");
                $('#divResult').slideToggle(500);
            } else {
                $('#btnReport2').val('Show Report');
                $('#spPrint').attr('style', 'display:none');

            }

        }

单击该按钮时,我将其文本更改为&#34;隐藏报告&#34;。但是,当我再次点击它时,在调试时,btnReport2.Text属性仍设置为&#34;显示报告&#34;这对我来说很奇怪,因为它会显示&#34;隐藏报告&#34;。

关于这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

您仅在客户端而非服务器端更改了按钮的值。这就是为什么在服务器端进行调试时值仍然保持不变的原因。