前台代码:
<link href="../ExtJs/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script src="../ExtJs/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="../ExtJs/ext-all.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
Ext.onReady(function () {
//初始化提示框
Ext.QuickTips.init();
var frm = new Ext.FormPanel({
url: '../Ashx/FormPanel.ashx',
title: '提交表单',
layout: 'form',
frame: true,
renderTo:Ext.getBody(),
items: [{
xtype: 'textfield',
fieldLabel: '用户名',
name: 'userName',
//empty: '输入用户名',
//allowBlank: false,
id: 'user'
}],
buttons: [{
text: '确定',
handler: function () {
frm.getForm().submit({
waitMsg:'保存中,请稍后...'
});
}
}, {
text: '取消',
handler: function () {
alert('事件');
}
}]
});
});
</script>
<script src="../ExtJs/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="../ExtJs/ext-all.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
Ext.onReady(function () {
//初始化提示框
Ext.QuickTips.init();
var frm = new Ext.FormPanel({
url: '../Ashx/FormPanel.ashx',
title: '提交表单',
layout: 'form',
frame: true,
renderTo:Ext.getBody(),
items: [{
xtype: 'textfield',
fieldLabel: '用户名',
name: 'userName',
//empty: '输入用户名',
//allowBlank: false,
id: 'user'
}],
buttons: [{
text: '确定',
handler: function () {
frm.getForm().submit({
waitMsg:'保存中,请稍后...'
});
}
}, {
text: '取消',
handler: function () {
alert('事件');
}
}]
});
});
</script>
后台代码 :
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
//暂停5秒,用于测试等待提示框
System.Threading.Thread.Sleep(5000);
if (context.Request["userName"] == "")
{
//返回验证不成功
context.Response.Write("{success:false,errors:{userName:'不能为空'}}"); //这里的errors 是后来验证,在前台显示的 注意格式,控件名称:‘错误信息‘
}
else
{
//返回操作成功
context.Response.Write("{success:true,msg:'操作成功'}");
}
}
context.Response.ContentType = "text/plain";
//暂停5秒,用于测试等待提示框
System.Threading.Thread.Sleep(5000);
if (context.Request["userName"] == "")
{
//返回验证不成功
context.Response.Write("{success:false,errors:{userName:'不能为空'}}"); //这里的errors 是后来验证,在前台显示的 注意格式,控件名称:‘错误信息‘
}
else
{
//返回操作成功
context.Response.Write("{success:true,msg:'操作成功'}");
}
}