簡體   English   中英

ASP.NET-從后面的代碼評估按鈕值

[英]ASP.NET - evaluating button value from code behind

我有一個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');

            }

        }

單擊按鈕后,我將其文本更改為“隱藏報告”。 但是,當我在調試時再次單擊它時,btnReport2.Text屬性仍然設置為“ Show report”,這對我來說很奇怪,因為它顯示“ Hide report”。

關於這個問題有什么想法嗎?

您僅在客戶端而非服務器端更改了button的值。 這就是為什么在服務器端進行調試時值仍然保持不變的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM