在此站点上已多次讨论此问题,但没有找到解决问题的方法。
我已经执行了以下步骤。
1.创建了一个JS函数。
function showModal() {
alert("called");
}
2.在.aspx文件中添加了脚本管理器
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
3.在.cs文件中创建一个方法
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
protected void register_user(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "showModal", "javascript:showModal(); ", true);
log.Debug("register_user is called");
}
但这不是在调用JS函数。
参考方案
可能是由于您尚未关闭javascript函数:
function showModal() {
alert("called");
}
或者,您也可以尝试以下操作:
替换此行:
Page.ClientScript.RegisterStartupScript(this.GetType(), "showModal", "javascript:showModal(); ", true);
与
Page.ClientScript.RegisterStartupScript(this.GetType(), "Message", "showModal(); ", true); // correct
.NET C#Webbrowser填充输入,不带ID或类名 - javascript我需要在网络浏览器中填写一个输入,但这不起作用。我认为必须使用name属性来完成,但是怎么做呢?foreach (HtmlElement login in webBrowser1.Document.GetElementsByTagName("input")) { if (login.GetAttribute("name"…
获取JavaScript值到C#字符串 - javascript是否可以在C#中执行类似的操作?该值为“ 10/05/2014”string jsValue = javascript("$('#EstimatedStartDate').val()"); 参考方案 您能否更详细地阐明您要做什么。看来您正在尝试从javascript(客户…
ASP.NET-如何更改JSON序列化的方式? - javascript我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …
Javascript-从当前网址中删除查询字符串 - javascript单击提交按钮后,我需要从网址中删除查询字符串值。我可以用jQuery做到这一点吗?当前网址:siteUrl/page.php?key=value 页面提交后:siteUrl/page.php 实际上,我已经从另一个带有查询字符串的页面着陆到当前页面。我需要在页面首次加载时查询字符串值以预填充一些详细信息。但是,一旦我提交了表格,我就需要删除查询字符串值。我已…
在JavaScript中运行方法C# - javascript打扰一下,我有这种C#asp方法。受保护的无效btnSave_Click(对象发送者,EventArgs e)有谁知道我该如何发送脚本给您?可以办到?。 javascript大神给出的解决方案 是的,那可以做到。为此,您在.aspx.cs页中创建了函数,然后单击保存按钮上的代码将其复制到函数中,然后执行以下步骤。//Call cs method from J…