aspx页面javascript的几个trick
|
日期:2005年10月31日 作者: 查看:[大字体
中字体 小字体]
|
这样,通过javscript调用theform.submit();来submit form,postback,但是,theform.submit将不会触发form的onsubmit事件!
这是微软的一个bug。
解决的方法可以看这里:http://www.devhawk.net/art_submitfirefixup.ashx,这里提供了一个dll及源代码,使用的时候,在project的reference里加入这个dll,然后在web.config中加上一段 <httpModules> <add type="DevHawk.Web.SubmitFireFixupModule,SubmitFireFixupModule" name="SubmitFireFixupModule" /> </httpModules> 就可以了。
3、一个应用。
常常听到抱怨,说如果在Browser端用javascript改动了某个<select>元素,那么,它对应的Server端的DropDownList不能得知这个更新。
这种情况可能出现在“级联”的DropDownList中,比如第一个DropDownList是省份,第二个是城市;也可能出现在,从第一个DropDownList选择某些项加入到第二个DropDownList中。
对此使用以上的技术,我做了一个这样的解决方案(类似于ViewState的方法):
一、我定义了一个长宽都是0的TextBox txtWrap,并把所有我想处理的DropDownList都加上AthosOsw="True" 这样的属性,准备处理。 二、参照上面2.2的内容,我加入了SubmitFireFixupModule,来保证触发form的onsubmit事件。 三、form的onsubmit事件将执行javascript函数fcnAthosOnSubmitWrap,它将遍历AthosOsw属性为True的DropDownList,记下数据,最后合并起来放到txtWrap里,其实这就是一个序列化的过程。代码如下: function fcnAthosOnSubmitWrap() { txtWrap = document.all["txtWrap"];
var i; var strWrap = ''; for(i=0;i<document.all.length;i++) { ctrl = document.all[i]; if(ctrl.tagName.toUpperCase() == 'SELECT' && typeof(ctrl.AthosOsw) != 'undefined' ) { if(ctrl.AthosOsw.toUpperCase() == 'TRUE') { strWrap += fcnAthosWrapSelect(ctrl) + '&&&'; } } }
if(strWrap.length>3) txtWrap.value = strWrap.substring(0, strWrap.length-3); };
//AthosOsw function fcnAthosWrapSelect(ctrlSelect) { var i; var strWrapSelect = ctrlSelect.id + '&' + ctrlSelect.tagName; var strValue=''; var strText=''; for(i=0; i<ctrlSelect.options.length; i++) { strValue = ctrlSelect.options[i].value; strText = ctrlSelect.options[i].text; strWrapSelect += '&&' + i + '&' + strValue.replace(/&/g, '%26') + '&' + strText.replace(/&/g, '%26'); }; return strWrapSelect; };
四、form的Page_Load中调用clsCommon.UnwrapControl(this, txtWrap.Text);来反序列化。clsCommon是我的工具类,UnwrapControl方法代码如下:
上一篇:ASP教程
下一篇:使用正则表达式实现模式图片新闻.ASP
|
| aspx页面javascript的几个trick 相关文章: |
|
|
|
| aspx页面javascript的几个trick 相关软件: |
|
|
|