JS调用后台事件?
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApp.positionManagement.WebForm2" %>
后台:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApp.positionManagement
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bindhtml();
}
public void bindhtml()
{
Response.Write("<html>");
Response.Write("<head>");
Response.Write("<title>测试</title>");
Response.Write("<script type=\"text/javascript\">");
Response.Write("function cheshi(){");
Response.Write("alert(\"进入1\");");
Response.Write("document.form1.action=\"Button1_Click\";");
Response.Write("document.form1.submit();");
Response.Write("alert(\"进入2\");");
Response.Write("}");
Response.Write("</script>");
Response.Write("</head>");
Response.Write("<body>");
string path = HttpContext.Current.Server.MapPath("~/positionManagement/WebForm2.aspx");
Response.Write(path);
Response.Write("<form name=\"form1\" action=\"" + path + "\" id=\"form1\">");
Response.Write("<div>");
Response.Write("<input id=\"btnAdd\" type=\"button\" value=\"确定\" onclick=\"return cheshi()\" />");
Response.Write("</div>");
Response.Write("<form>");
Response.Write("<from>");
Response.Write("</body>");
Response.Write("</html>");
}
public void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('测试成功!');</script>");
}
}
}
老是报个找不到路径?怎么解决呢?