public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
[System.Web.Services.WebMethod]
public static void AddInfo()
{
twoManager tm = new twoManager();
two t = new two();
t.Username = HttpContext.Current.Request.QueryString["username"].ToString();
t.Userpwd = HttpContext.Current.Request.QueryString["userpwd"].ToString();
t.Age = HttpContext.Current.Request.QueryString["age"].ToString();
t.Sex = HttpContext.Current.Request.QueryString["sex"].ToString();
tm.AddInfo(t);
}
}
{
protected void Page_Load(object sender, EventArgs e)
{ }
[System.Web.Services.WebMethod]
public static void AddInfo()
{
twoManager tm = new twoManager();
two t = new two();
t.Username = HttpContext.Current.Request.QueryString["username"].ToString();
t.Userpwd = HttpContext.Current.Request.QueryString["userpwd"].ToString();
t.Age = HttpContext.Current.Request.QueryString["age"].ToString();
t.Sex = HttpContext.Current.Request.QueryString["sex"].ToString();
tm.AddInfo(t);
}
}
解决方案 »
- 急需解决!!!关于ASP.NET,关于在一个主页面中点击按钮可以弹出含有可以编辑操作的小窗口!!!!
- 在VS2010中如何添加引用BarcodeX.dll
- 用什么语言做网址导航网站才是最合适的!?
- 求救::如何删除一个虚拟目录的代码?
- VS2005中的水晶报表问题(WEB)
- 在客户端改变CheckBox的值,去改变ListBox的选项全选或全不选。
- 用XML打广告打不出来,代码错了?进来帮我UP就给分
- 请问一条Update语句怎么写,高手帮忙!
- 页面回车按键问题
- 请问: 前台用<iframe id="Composition" ></iframe>,在cs文件中如何引用该控件?
- 绑定的数据突然全部错乱!!!!!
- 求帮助修改代码,用户注册界面
<title>无标题页</title>
<script type="text/javascript">
function Add()
{
PageMethods.AddInfo();
}
</script>
</head>
<body>
<form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<div>
用户名<input type="text" name="username" id="uname" /><br />
密码<input type="text" name="userpwd" id="upwd"/><br />
年龄<input type="text" name="age" id="uage" /><br />
性别<input type="text" name="sex" id="usex"/><br />
<input type="button" name="Button" value="添加" onclick="Add()"/>
</div>
</form>
</body>
-----------------------------------
运行后报错Microsoft JScript 运行时错误: Sys.Net.WebServiceFailedException: 服务器方法“AddInfo”失败,并发生以下错误: System.NullReferenceException-- 未将对象引用设置到对象的实例。高手指教
function Add()
{
PageMethods.AddInfo(AddSeccce);
}functin AddSeccce()
{
alert('添加成功');
}
这样试试
twoManager tm = new twoManager();
PageMethods.AddInfo();
这个当中的。还有你如果在静态方法中不能实例化,那你把那个要调用的类改为静态的类,方法也改为静态的方法。
{
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof("WebForm1")); }
[System.Web.Services.WebMethod]
public static void AddInfo()
{
....
}
}
<head id="Head1" runat="server">
<title>无标题页</title>
<script type="text/javascript">
function Add()
{
WebForm1.AddInfo();
}
</script>
</head>
1.web.config中的配置
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>
public void AddInfo()
{
twoManager tm = new twoManager();
two t = new two();
t.Username = HttpContext.Current.Request.QueryString["username"].ToString();
t.Userpwd = HttpContext.Current.Request.QueryString["userpwd"].ToString();
t.Age = HttpContext.Current.Request.QueryString["age"].ToString();
t.Sex = HttpContext.Current.Request.QueryString["sex"].ToString();
tm.AddInfo(t);
}
--------------------------
前台
<input type="button" name="Button" value="添加" onclick="<%=AddInfo()%>"/>
<div>
用户名<input type="text" name="username" id="uname" /><br />
密码<input type="text" name="userpwd" id="upwd"/><br />
年龄<input type="text" name="age" id="uage" /><br />
性别<input type="text" name="sex" id="usex"/><br />
<input type="button" name="Button" value="添加" onclick="Add($get('uname').value, $get('upwd').value, $get('uage').value, $get('usex').value"/>这么传不行吗?服务器端用string参数接着不就行了吗?$get('id').value是document.getElementById('id')的asp.net ajax缩写方式。
<input type="button" name="Button" value="添加" onclick="<%=AddInfo()%>"/>