成功JavaScript函数中的警报(结果)显示的对话框只是页面的整个HTML代码。这很奇怪。我无法让客户端在C#中调用服务器端功能。
用于打印服务器端功能中给出的字符串。
submit.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type='text/javascript'>
function GetName() {
PageMethods.Name(Success, Failure);
}
function Success(result) {
alert(result);
}
function Failure(error) {
alert(error);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />
<div>
<asp:Button ID="Button1" runat="server" Text="Get Name" OnClientClick='GetName();return false;' />
</div>
</form>
</body>
</html>
submit.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Drawing.Layout;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization;
//needed for SQL access
using System.Data.SqlClient;
using System.Collections;
using System.Net;
using PDFCreator;
namespace theform
{
public partial class submit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//functions fun = new functions();
//fun.Main();
}
[WebMethod]
public static string Name()
{
string Name = "Hello Rohatash Kumar";
return Name;
}
// <input id="clickMe" type="button" value="clickme" onclick="create_array();" />
}
}
答案 0 :(得分:0)
你可以使用onclick按钮事件来显示alert.this是另一种方法
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Insert is successfull')", true);