English 中文(简体)
Call Javagust function from global.asax.c
原标题:Call JavaScript function from global.asax.cs

我想把 Java本功能(内部显示对错误讯息的不安)从全球引来。 页: 1 我的守则是,我正在“全球”——《瓦克斯-茨案》中尝试的。

protected void Application_Error(object sender, EventArgs e)
{
    System.Web.UI.Page mypage = (System.Web.UI.Page)HttpContext.Current.Handler;
    mypage.RegisterStartupScript("alert", "<script language=javascript>alert( test );</script>");
}

But it is not calling the alert nor giving any error or warning message in Firebug and the Google Chrome console. How can JavaScript code be called?

最佳回答

当时有两种不同的错误。

  1. Errors that are thrown by the compiler.
  2. Errors that are thrown by your program.

www.un.org/Depts/DGACM/index_spanish.htm 例如,汇编者可在处发现任何错误,因此无法在守则后面找到字面控制。 在这种情况下,你的网页甚至不存在,现在也找不到,也没有办法使Java文本警惕。

www.un.org/Depts/DGACM/index_spanish.htm 举例来说,在你的节目“

页: 1 HttpContext. 现任。 Handler is NOT a page .

总的来说,申请 Error用于捕获和记录unhandled mis,以在以后解决这些错误,并可能向用户显示一个更好的错误网页。

如果你只想看到你在欺骗方面的错误,你可以使用诸如:

void Application_Error(object sender, EventArgs e)
{
    Exception LastOneError = Server.GetLastError();
    if (LastOneError != null)
    {
        Debug.Fail("Unhandled error: " + LastOneError.ToString());
        LogTheError(LastOneError);
    }
}

Custom error page

我可以认为这样作的唯一途径是,在错误出现在解释错误的新页上时,再作解释,但这正是习惯错误页已经做的。

More

This is the way I handle my custom errors and stay on the same page. The file check is to avoid possible close loop that can crash the pool.

  string cTheFile = HttpContext.Current.Request.Path;

  if (!cTheFile.EndsWith("ErrorHandlePage.aspx"))
      Server.Transfer("~/ErrorHandlePage.aspx");
问题回答

这本页上写了字,带上了电文箱。 我把它放在一个全球。 缩略语 以零错误进行试验:

void Application_Error(object sender, EventArgs e)
{
    String ErrorStr = "Application_Error " + Server.GetLastError().Message;

    Response.Write("<h2>Global Page Error</h2>
");
    Response.Write("<p>" + ErrorStr + "</p>
");

    Response.Write("<Script Language= javascript > alert( Hello );</script>");

    // Clear the error from the server
    Server.ClearError();
}

Quick answer is you can t.

全球没有网页。 ax no

https://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx” rel=“nofollow” 页: 1

我认为,你的问题是,在你登记该页的文字时,它太晚了。 该页标的寿命周期已经结束,不会给该页增加任何数据。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签