客户端函数返回HTML代码而不是服务器端返回值
Client Side function returning HTML Code instead of Server Side return value
成功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();" />
}
}
可以使用onclick按钮事件来显示警报吗?这是另一个方法
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Insert is successfull')", true);
相关文章:
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- Ajax post后数组在服务器端返回为空
- ASP.net自定义控件,下拉值必须在服务器端填充,所选值在返回时丢失
- Angularjs和服务器端返回值(PHP)
- 如何将客户端javascript返回值传递给ASP经典服务器端
- 如何在没有任何事件的情况下从 document.ready 上的服务器端检索值
- 将函数的 JavaScript 返回值存储到服务器端的相应 Asp Control OnClick 事件
- 从服务器端获取值并分配给 JavaScript 变量
- 获取Java Script返回到服务器端的值
- 通过json从服务器端返回sum
- asp.net使用javascript操作表单字段值,但无法在服务器端获取值
- ajax函数,用于从2个服务器端脚本向2个DOM目标返回值
- 更新. .需要一个Ajax示例,说明客户端如何在不回发的情况下从服务器端获取值
- 如何确保从服务器端返回的img不会被拦截
- JavaScript websocket可以从服务器获得返回值吗?
- Javascript客户端返回值到asp.net服务器端
- 服务器以CherryPy的形式返回值给客户端
- 如何将字符串从javascript传递到服务器?然后从asp.net web表单中的服务器获取返回值
- 客户端函数返回HTML代码而不是服务器端返回值
- AJAX-我需要在服务器端返回一个完整的HTML文档吗