『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复

几点说明


  1. 这里所谓的Asp.NET后台,是指Asp.NET页面的aspx.cs文件的代码
  2. 请不要直接复制代码,由于各人环境不同,可能会产生异常
  3. 本篇中的代码说明中,将省略之前文章中所描述过的内容
  4. 下一篇记录如何实现表单控件事件的侦听

 

 

 

最简单的提交与后台消息回复


IDE: VS2010 SP1

ExtJS版本:3.4.0

 

<!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>
    <title>『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复</title>
    <!-- Common Libs -->
    <link href="../Common/ext-all.css" rel="stylesheet" type="text/css" />
    <script src="../Common/ext-base-debug.js" type="text/javascript"></script>
    <script src="../Common/ext-all-debug-w-comments.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
    Ext.onReady(function () {
        var frm = new Ext.FormPanel({
            renderTo: document.body,
            title: '『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复 —— http://www.cnblogs.com/sitemanager/',
            url: '../jsonresponse.aspx',
            autoWidth: 'true',
            buttons: [{
                text: 'Save',
                handler: function () {
                    frm.getForm().submit({
                        success: function (f, a) {
                            Ext.Msg.alert('Success', 'It worked');
                        },
                        failure: function (f, a) {
                            Ext.Msg.alert('Warning', 'Error');
                        }
                    });
                }
            }, {
                text: 'Reset',
                handler: function () {
                    frm.getForm().reset();
                }
            }]
        });
    });
</script>
</body>
</html>


using System;

namespace csdemo.extjs
{
    public partial class jsonresponse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("{success: true}");
        }
    }
}

说明:

  1. buttons 配置项是用于配置表单按钮的,之后的操作都是利用表单按钮的handler来进行的
  2. frm.getForm().submit() 与 frm.getForm.reset() 分别对应于Html表单的submit与reset操作
  3. 使用getForm用于获取对应表单
  4. success 与 failure 分别对应表单提交的两个状态,其后可跟函数,我这里放的是匿名函数。

 

 

 

效果图

image

 

 

 

 

 

 

带有回执消息的实现


<!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>
    <title>『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复</title>
    <!-- Common Libs -->
    <link href="../Common/ext-all.css" rel="stylesheet" type="text/css" />
    <script src="../Common/ext-base-debug.js" type="text/javascript"></script>
    <script src="../Common/ext-all-debug-w-comments.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
    Ext.onReady(function () {
        // Provides attractive and customizable tooltips for any element. 
        Ext.QuickTips.init();

        var classesStore = new Ext.data.SimpleStore({
            fields: ['id', 'class'],
            data: [['0', 'ExtJS 3.3.0'], ['1', 'ExtJS 3.4.0'], ['2', 'ExtJS 4.0']]
        });

        var frm = new Ext.FormPanel({
            renderTo: document.body,
            title: '『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复 —— http://www.cnblogs.com/sitemanager/',
            url: '../jsonresponse.aspx',
            autoWidth: 'true',
            buttons: [{
                text: 'Save',
                handler: function () {
                    frm.getForm().submit({
                        success: function (form, action) {

                            frm.getForm().findField('title').setValue(action.result.title);
                            frm.getForm().findField('author').setValue(action.result.author);
                            frm.getForm().findField('email').setValue(action.result.email);
                            frm.getForm().findField('site').setValue(action.result.site);
                            frm.getForm().findField('contentEssay').setValue(action.result.contentEssay);

                            Ext.Msg.alert('Success', 'Loaded all!');
                        },
                        failure: function (form, action) {
                            Ext.Msg.alert('Warning', action.result.errorMsg);
                        }
                    });
                }
            }, {
                text: 'Reset',
                handler: function () {
                    frm.getForm().reset();
                }
            }],
            items: [{
                xtype: 'textfield',
                fieldLabel: '文章标题',
                name: 'title',
                // Specify false to validate that the value's length is > 0 (defaults to true)
                allowBlank: 'false',
                width: 300,
                // A config object containing one or more event handlers to be added to this object during initialization.
                listeners: {
                    specialkey: function (f, e) {
                        if (e.getKey() == e.ENTER) {
                            Ext.Msg.alert('Listen Success!', e.getKey);
                        }
                    }
                }
            }, {
                xtype: 'textfield',
                fieldLabel: '作者',
                name: 'author',
                width: 300
            }, {
                xtype: 'textfield',
                fieldLabel: '邮箱',
                name: 'email',
                // The error text to display when the email validation function returns false. 
                vtype: 'emailText',
                allowBlank: 'true',
                width: 300
            }, {
                xtype: 'textfield',
                fieldLabel: '主页',
                name: 'site',
                // The error text to display when the url validation function returns false. 
                vtype: 'urlText',
                allowBlank: 'true',
                width: 300
            }, {
                xtype: 'numberfield',
                fieldLabel: '发布次数',
                name: 'publishNumber',
                width: 300
            }, {
                xtype: 'combo',
                fieldLabel: '文章分类',
                name: 'class',
                /* Acceptable values are: 
                *      'remote' : Default 
                *          Automatically loads the store the first time the trigger is clicked. If you do not want the store to be automatically loaded the first time the trigger is clicked, set to 'local' and manually load the store. To force a requery of the store every time the trigger is clicked see lastQuery.
                *      'local' : 
                *          ComboBox loads local data
                */
                mode: 'local',
                // The data source to which this combo is bound (defaults to undefined).
                store: classesStore,
                // The underlying data field name to bind to this ComboBox
                displayField: 'class',
                width: 300
            }, {
                xtype: 'datefield',
                fieldLabel: '发布日期',
                name: 'publishDate',
                // An array of days to disable, 0 based (defaults to null).
                // disable Sunday and Saturday:
                disabledDays: [0, 6],
                width: 300
            }, {
                xtype: 'timefield',
                fieldLabel: '发布时间',
                increment: 15,
                name: 'publishTime',
                width: 300
            }, {
                xtype: 'radio',
                boxLabel: '随笔',
                fieldLabel: '文章类型',
                // Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
                name: 'essayClass',
                width: 300
            }, {
                xtype: 'radio',
                boxLabel: '文章',
                name: 'essayClass',
                width: 300
            }, {
                xtype: 'checkbox',
                fieldLabel: '发布到首页',
                name: 'publishToSiteHome',
                width: 300
            }, {
                xtype: 'textarea',
                fieldLabel: '摘要',
                name: 'abstractEssay',
                width: 500,
                allowBlank: 'true',
                autoScroll: 'true',
                height: 30
            }, {
                // Provides a lightweight HTML Editor component.
                xtype: 'htmleditor',
                fieldLabel: '正文',
                name: 'contentEssay',
                width: 500,
                allowBlank: 'false',
                autoScroll: 'true',
                height: 300
            }]
        });
    });
</script>
</body>
</html>


using System;
using System.Web.Script.Serialization;

namespace csdemo.extjs
{
    public partial class jsonresponse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int resMode;
            JavaScriptSerializer js = new JavaScriptSerializer();
            responseMsg resMsg = new responseMsg();

            resMode = 2;

            switch (resMode)
            {
                case 1:
                    resMsg.success = false;
                    resMsg.errorMsg = "Test the Error Message";
                    Response.Write(js.Serialize(resMsg));
                    break;
                case 2:
                    blogEssay bl = new blogEssay();
                    bl.success = true;
                    bl.title = "『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复";
                    bl.author = "Aaron";
                    bl.contentEssay = "test";
                    bl.site = "http://www.cnblogs.com/sitemanager/";
                    Response.Write(js.Serialize(bl));
                    break;
                default:
                    resMsg.success = false;
                    resMsg.errorMsg = "请先传入参数!";
                    Response.Write(js.Serialize(resMsg));
                    break;
            }
        }
    }

    public class responseMsg
    {
        private bool _success;

        public bool success
        {
            get { return _success; }
            set { _success = value; }
        }
        private string _errorMsg;

        public string errorMsg
        {
            get { return _errorMsg; }
            set { _errorMsg = value; }
        }
    }

    public class blogEssay : responseMsg
    {
        private string _title;

        public string title
        {
            get { return _title; }
            set { _title = value; }
        }
        private string _author;

        public string author
        {
            get { return _author; }
            set { _author = value; }
        }
        private string _email;

        public string email
        {
            get { return _email; }
            set { _email = value; }
        }
        private string _site;

        public string site
        {
            get { return _site; }
            set { _site = value; }
        }
        private int _publishNumber;

        public int publishNumber
        {
            get { return _publishNumber; }
            set { _publishNumber = value; }
        }
        private string _abstractEssay;

        public string abstractEssay
        {
            get { return _abstractEssay; }
            set { _abstractEssay = value; }
        }
        private DateTime _publishDate;

        public DateTime publishDate
        {
            get { return _publishDate; }
            set { _publishDate = value; }
        }
        private string _contentEssay;

        public string contentEssay
        {
            get { return _contentEssay; }
            set { _contentEssay = value; }
        }
    }
}

说明:

  1. 使用getForm().findField(‘表单内控件的name属性').setValue(想要设置的值)
  2. a.result 代表后台回传来的结果集
  3. a.result.xxxx 表示结果集中的某个指定的JSON数据项名的值
  4. 使用JavaScriptSerializer对象来序列化相应类型为JSON数据格式,用于传回给前台

 

效果图

image

 

 

 

 

前台向后台传参数


<!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>
    <title>『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复</title>
    <!-- Common Libs -->
    <link href="../Common/ext-all.css" rel="stylesheet" type="text/css" />
    <script src="../Common/ext-base-debug.js" type="text/javascript"></script>
    <script src="../Common/ext-all-debug-w-comments.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
    Ext.onReady(function () {
        // Provides attractive and customizable tooltips for any element. 
        Ext.QuickTips.init();

        var classesStore = new Ext.data.SimpleStore({
            fields: ['id', 'class'],
            data: [['0', 'ExtJS 3.3.0'], ['1', 'ExtJS 3.4.0'], ['2', 'ExtJS 4.0']]
        });

        var frm = new Ext.FormPanel({
            renderTo: document.body,
            title: '『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复 —— http://www.cnblogs.com/sitemanager/',
            url: '../jsonresponse.aspx',
            autoWidth: 'true',
            buttons: [{
                text: '加载表单',
                handler: function () {
                    frm.getForm().load({
                        url: '../jsonresponse.aspx',
                        params: {
                            resMode: 3
                        }
                    });
                }
            }, {
                text: '参数互传',
                handler: function () {
                    frm.getForm().submit({
                        url: '../jsonresponse.aspx',
                        params: {
                            resMode: 4
                        },
                        success: function (form, action) {
                            Ext.Msg.alert("Success", action.result.errorMsg);
                        },
                        failure: function (form, action) {
                            Ext.Msg.alert('Warning', action.result.errorMsg);
                        }
                    });
                }
            }, {
                text: 'Save',
                handler: function () {
                    frm.getForm().submit({
                        url: '../jsonresponse.aspx',
                        params: {
                            resMode: 1
                        },
                        success: function (form, action) {

                            frm.getForm().findField('title').setValue(action.result.title);
                            frm.getForm().findField('author').setValue(action.result.author);
                            frm.getForm().findField('email').setValue(action.result.email);
                            frm.getForm().findField('site').setValue(action.result.site);
                            frm.getForm().findField('contentEssay').setValue(action.result.contentEssay);

                            Ext.Msg.alert('Success', 'Loaded all!');
                        },
                        failure: function (form, action) {
                            Ext.Msg.alert('Warning', action.result.errorMsg);
                        }
                    });
                }
            }, {
                text: 'Reset',
                handler: function () {
                    frm.getForm().reset();
                }
            }],
            items: [{
                xtype: 'textfield',
                fieldLabel: '文章标题',
                name: 'title',
                // Specify false to validate that the value's length is > 0 (defaults to true)
                allowBlank: 'false',
                width: 300,
                // A config object containing one or more event handlers to be added to this object during initialization.
                listeners: {
                    specialkey: function (f, e) {
                        if (e.getKey() == e.ENTER) {
                            Ext.Msg.alert('Listen Success!', e.getKey);
                        }
                    }
                }
            }, {
                xtype: 'textfield',
                fieldLabel: '作者',
                name: 'author',
                width: 300
            }, {
                xtype: 'textfield',
                fieldLabel: '邮箱',
                name: 'email',
                // The error text to display when the email validation function returns false. 
                vtype: 'emailText',
                allowBlank: 'true',
                width: 300
            }, {
                xtype: 'textfield',
                fieldLabel: '主页',
                name: 'site',
                // The error text to display when the url validation function returns false. 
                vtype: 'urlText',
                allowBlank: 'true',
                width: 300
            }, {
                xtype: 'numberfield',
                fieldLabel: '发布次数',
                name: 'publishNumber',
                width: 300
            }, {
                xtype: 'combo',
                fieldLabel: '文章分类',
                name: 'class',
                /* Acceptable values are: 
                *      'remote' : Default 
                *          Automatically loads the store the first time the trigger is clicked. If you do not want the store to be automatically loaded the first time the trigger is clicked, set to 'local' and manually load the store. To force a requery of the store every time the trigger is clicked see lastQuery.
                *      'local' : 
                *          ComboBox loads local data
                */
                mode: 'local',
                // The data source to which this combo is bound (defaults to undefined).
                store: classesStore,
                // The underlying data field name to bind to this ComboBox
                displayField: 'class',
                width: 300
            }, {
                xtype: 'datefield',
                fieldLabel: '发布日期',
                name: 'publishDate',
                // An array of days to disable, 0 based (defaults to null).
                // disable Sunday and Saturday:
                disabledDays: [0, 6],
                width: 300
            }, {
                xtype: 'timefield',
                fieldLabel: '发布时间',
                increment: 15,
                name: 'publishTime',
                width: 300
            }, {
                xtype: 'radio',
                boxLabel: '随笔',
                fieldLabel: '文章类型',
                // Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
                name: 'essayClass',
                width: 300
            }, {
                xtype: 'radio',
                boxLabel: '文章',
                name: 'essayClass',
                width: 300
            }, {
                xtype: 'checkbox',
                fieldLabel: '发布到首页',
                name: 'publishToSiteHome',
                width: 300
            }, {
                xtype: 'textarea',
                fieldLabel: '摘要',
                name: 'abstractEssay',
                width: 500,
                allowBlank: 'true',
                autoScroll: 'true',
                height: 30
            }, {
                // Provides a lightweight HTML Editor component.
                xtype: 'htmleditor',
                fieldLabel: '正文',
                name: 'contentEssay',
                width: 500,
                allowBlank: 'false',
                autoScroll: 'true',
                height: 300
            }]
        });
    });
</script>
</body>
</html>


using System;
using System.Web.Script.Serialization;

namespace csdemo.extjs
{
    public partial class jsonresponse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int resMode;
            JavaScriptSerializer js = new JavaScriptSerializer();
            responseMsg resMsg = new responseMsg();
            blogEssay bl = new blogEssay();


            if (Request["resMode"] != null)
            {
                resMode = Convert.ToInt32(Request["resMode"]);
            }
            else
            {
                resMode = 2;
            }

            switch (resMode)
            {
                case 1:
                    resMsg.success = true;
                    resMsg.errorMsg = "表单接收成功!";
                    Response.Write(js.Serialize(resMsg));
                    break;
                case 2:
                    bl.success = true;
                    bl.title = "『ExtJS』表单(二)表单行为与Asp.NET页面的消息回复";
                    bl.author = "Aaron";
                    bl.contentEssay = "test";
                    bl.site = "http://www.cnblogs.com/sitemanager/";
                    Response.Write(js.Serialize(bl));
                    break;
                case 3:
                    resMsg.success = true;
                    resMsg.errorMsg = "Thank you for your reading!";
                    Response.Write(js.Serialize(resMsg));
                    break;
                case 4:
                    resMsg.success = true;
                    resMsg.errorMsg = "参数传入成功!";
                    Response.Write(js.Serialize(resMsg));
                    break;
                default:
                    resMsg.success = false;
                    resMsg.errorMsg = "请先传入参数!";
                    Response.Write(js.Serialize(resMsg));
                    break;
            }
        }
    }

    public class responseMsg
    {
        private bool _success;

        public bool success
        {
            get { return _success; }
            set { _success = value; }
        }
        private string _errorMsg;

        public string errorMsg
        {
            get { return _errorMsg; }
            set { _errorMsg = value; }
        }
    }

    public class blogEssay : responseMsg
    {
        private string _title;

        public string title
        {
            get { return _title; }
            set { _title = value; }
        }
        private string _author;

        public string author
        {
            get { return _author; }
            set { _author = value; }
        }
        private string _email;

        public string email
        {
            get { return _email; }
            set { _email = value; }
        }
        private string _site;

        public string site
        {
            get { return _site; }
            set { _site = value; }
        }
        private int _publishNumber;

        public int publishNumber
        {
            get { return _publishNumber; }
            set { _publishNumber = value; }
        }
        private string _abstractEssay;

        public string abstractEssay
        {
            get { return _abstractEssay; }
            set { _abstractEssay = value; }
        }
        private DateTime _publishDate;

        public DateTime publishDate
        {
            get { return _publishDate; }
            set { _publishDate = value; }
        }
        private string _contentEssay;

        public string contentEssay
        {
            get { return _contentEssay; }
            set { _contentEssay = value; }
        }
    }
}

 

说明:

  1. 在submit()函数中,可以使用 url 来重新指定表单回传的目标页面
  2. 可以使用 params 来指定回传的参数,默认为post方式
  3. 有后台Asp.NET中,直接使用 Request[‘参数名 ']来获取传入的值
  4. 注意,从前台来的值,一般情况下是string型的,可能会需要进行一些格式上的转换后,才能使用

 

 

效果图

image

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值