[英]Calling Javascript function in C#
How am I able to show an alert to the user on a Web Application in C#?我如何能够在 C# 中的 Web 应用程序上向用户显示警报? I'm trying to do so by calling on a JS function within the C# I'm writing, but am unsure of how to do so since Page.ClientScript isn't being recognized.我试图通过调用我正在编写的 C# 中的 JS 函数来做到这一点,但我不确定如何这样做,因为 Page.ClientScript 未被识别。 Do I need a different namespace included?我需要包含不同的命名空间吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Transactions;
using System.Web.Http;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
.
.
.
while (physAuthToUpdate.start_date < physAuthToUpdate.end_date)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "print", "<script>showAlertWindow('Error: End date cannot come before begin date.');</script>");
}
.
.
.
Here is a good example.这是一个很好的例子。 https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.clientscriptmanager?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.clientscriptmanager?view=netframework-4.8
And it may also be possible to simple use following if you want to show the alert inline:如果您想内联显示警报,也可以简单地使用以下方法:
Response.Write("<script>alert('hello');</script>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.