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

时间:2022-08-25 22:05:39

I've got an asp button which is calling a C# method when the user clicks on it :

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

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

The following method is called :

调用以下方法:

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

            }

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

As you can see, at the end of the method, I'm calling a jQuery script :

如您所见,在方法结束时,我正在调用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');

            }

        }

When the button is clicked, I change its text to "Hide report". However, when I'm clicking on it again, while debugging, the btnReport2.Text property is still set to "Show report" which is strange for me because it displays "Hide report".

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

Any idea about this issue?

对这个问题有什么想法吗?

1 个解决方案

#1


0  

You have changed the value of button only on client side not on server side. That's why value still remains same while debugging on server side.

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

#1


0  

You have changed the value of button only on client side not on server side. That's why value still remains same while debugging on server side.

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