您的位置:首页 > Web前端 > JavaScript

extjs的 FormPanel 保存提交数据

2011-05-15 23:15 246 查看
<link href="ext-3.1.1/resources/css/ext-all.css" rel="Stylesheet" />
<script type="text/javascript" src="ext-3.1.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.1.1/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
var form = new Ext.form.FormPanel({
title: "注册用户",
defaultType: "textfield",//默认是textfield
labelAlign: "right",//右对其
url: "12form.aspx",//提交的服务端页面返回json类型
items: [{ fieldLabel: "用户名", name: "usrname" }, { fieldLabel: "年龄", name: "age" }, { xtype: "datefield", name: "birth", fieldLabel: "出生日期", format: "Y-m-d"}],

renderTo: "form",
buttons: [{ text: "保存", handler: function() {

form.getForm().submit({ success: function(form, action) {
alert(action.result.msg);

}, failure: function() { alert("失败") }
});
}

}]//success,failure返回成功失败状态。

})

})
</script>
</head>
<body>
<div id="form"></div>
</body>
</html>

12form.aspx 代码:

<%
string name = Request.Params["usrname"];
int age =int.Parse(Request.Params["age"]);
// DateTime bir = Convert.ToDateTime(Request.Params["birth"]);
bool tag=false;
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["mycon"].ToString();
try
{

using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{

string sql = "insert into tuser(UserName,age) values('" + name + "'," + age + ")";
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, con))
{
con.Open();

cmd.ExecuteNonQuery();
}

}
tag = true;
}
catch (Exception)
{
tag = false;
throw;
}

if (tag)
{
Response.Write("{success:true,msg:'添加成功'}");
}
else
{
Response.Write("{failed:true,msg:'添加失败'}");
}

%>

可以时间一个注册的功能!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: