开发者

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 (Except开发者_开发百科ion 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜