简体   繁体   English

单击按钮时未调用警报框

[英]Alert box not being called upon button click

I have a fairly simple code, a button click event, with the first line being a message box. 我有一个相当简单的代码,一个按钮单击事件,第一行是一个消息框。 When the button is clicked, the messagebox is not called. 单击该按钮时,不会调用该消息框。

protected void btnSubmitToCRM_Click(object sender, EventArgs e)
{
    try
    {
        if (!ValidateCoreValue())
        {
            return;
        }

        if (!ValidateOtherAppLicenses())
        {
            return;
        }

        GetTicketRequesterInfo();

        SendCRMEmail();

        ClearTextBoxes(Page.Controls);

    }
    catch (Exception ex)
    {
        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('btnSubmitToCRM_Click - 1" + ex.Message + "');", true);
    }
}

Any ideas? 有任何想法吗?

So, the idea is that the submit button throws up a javascript alert? 因此,想法是“提交”按钮引发了JavaScript警报? Well, you would need to register the client script in a different event than the one that is fired when the button is clicked. 好吧,您将需要在与单击按钮时触发的事件不同的事件中注册客户端脚本。

Think about the order of events here. 在这里考虑事件的顺序。 By the time you get into the btnSubmitToCRM_Click function the client has already posted back to the server. 在您进入btnSubmitToCRM_Click函数时,客户端已经回发到服务器。 Then you're trying to register the event on the client side to throw up the alert. 然后,您尝试在客户端注册该事件以引发警报。 Well, at that point it's too late. 好吧,到那时为时已晚。 The client has already clicked the button. 客户端已经单击了按钮。 The RegisterStartupScript method inserts Javascript into the page when whatever event it is called in is fired. 触发任何调用事件时,RegisterStartupScript方法都会将Javascript插入页面。 So, generally that has to happen when the page loads. 因此,通常必须在页面加载时发生。

I'd say try throwing the RegisterStartupScript call into your page load event and see if that helps. 我想说尝试将RegisterStartupScript调用扔到您的页面加载事件中,看看是否有帮助。

Update: So, if the intention is to find out what is going on in the code on the test server then you should either attach a remote debugger, write out exceptions to a common log using something like NLog or you could write out the exception message to an ASP:Label control on the page. 更新:因此,如果要找出测试服务器上代码中发生的事情,那么您应该附加一个远程调试器,使用NLog之类的东西将异常写到普通日志中,或者可以写出异常消息到页面上的ASP:Label控件。

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

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