使用ActionlessForm.cs重写Form后使得验证控件失效的解决方法

ActionlessForm.cs
 1 None.gif public   class  Form : HtmlForm
 2 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 3InBlock.gif        protected override void RenderAttributes(HtmlTextWriter writer)
 4ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 5InBlock.gif            writer.WriteAttribute("name", Name);
 6InBlock.gif            base.Attributes.Remove("name");
 7InBlock.gif
 8InBlock.gif            writer.WriteAttribute("method", Method);
 9InBlock.gif            base.Attributes.Remove("method");
10InBlock.gif
11InBlock.gif            Attributes.Render(writer);
12InBlock.gif
13InBlock.gif            base.Attributes.Remove("action");
14InBlock.gif
15InBlock.gif            if (base.ID != null)
16ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
17InBlock.gif                writer.WriteAttribute("id", ClientID);
18ExpandedSubBlockEnd.gif            }

19ExpandedSubBlockEnd.gif        }

20ExpandedBlockEnd.gif    }
目的主要是将Form中的Action去掉,让Url Rewrite在postback的时候能在IHttpModule中找到实际aspx文件,但在这样的环境下除了把Action去掉后也把验证控件的  οnsubmit="if (!ValidatorOnSubmit()) return false;"  也去掉。

想到一个笨的办法解决:
在postback的按钮,如
< asp:button id = " btnOK "  Runat = " server "  Text = " 确定 "   ></ asp:button >
在按钮外端添加
< span onclick = " if (!ValidatorOnSubmit()){return false;} " >< asp:button id = " btnOK "  Runat = " server "  Text = " 确定 "   ></ asp:button ></ span >
即可在点击按钮前先通过 if(!ValidatorOnSubmit()) return false; 这个验证后再执行postback

转载于:https://www.cnblogs.com/yuxiang9999/archive/2006/08/25/486415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值