简体   繁体   中英

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? 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. 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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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