也谈UpdatePanel与UrlRewrite一起work时出现Form Action属性的问题

简介:
首先感谢老赵写了一篇文章, http://www.cnblogs.com/JeffreyZhao/archive/2006/12/27/604373.aspx#post

其实出现这个问题,根本不是MS Ajax的失误,完全是我们没有用好URLRewrite这个东西的原因。

老赵的解决方法是重写了一个Form类,把原来的Form的Action给清空了。

能否正常工作我不知道,但是我认为“清空”,“利用默认属性”这样一类的做法是很危险的。~~~

重写Form类的,引用也有点麻烦,我觉的重写一个Page,比较方便。我在 www.365rss.cn 中的做法如下:

using  System;
using  System.IO;
using  System.Web;
using  System.Web.UI;
namespace  okpower.Utility
{
    
/// <summary>
    
/// URLRewrite 页面基类
    
/// 作者:Kai.Ma http://kaima.cnblogs.com
    
/// </summary>

    public class URLRewritePage : Page
    
{
        
public URLRewritePage()
        
{
        }


        
protected override void Render(HtmlTextWriter writer)
        
{            
            writer 
= new FormFixerHtmlTextWriter(writer.InnerWriter);
            
base.Render(writer);
        }

    }


    
internal class FormFixerHtmlTextWriter : System.Web.UI.HtmlTextWriter
    
{
        
private string _url;
        
internal FormFixerHtmlTextWriter(TextWriter writer)
            : 
base(writer)
        
{
            _url 
= HttpContext.Current.Request.RawUrl;
        }


        
public override void WriteAttribute(string name, string value, bool encode)
        
{
            
// 如果当前输出的属性为form标记的action属性,则将其值替换为重写后的虚假URL
            if (_url != null && string.Compare(name, "action"true== 0)
            
{
                value 
= _url;
            }


            
base.WriteAttribute(name, value, encode);
        }

    }


}
以后继承这个URLRewritePage就可以了,甚至可以进web.config设置,一劳永逸。

欢迎交流


本文转自Kai的世界,道法自然博客园博客,原文链接:http://www.cnblogs.com/kaima/archive/2006/12/27/604758.html,如需转载请自行联系原作者。

目录
相关文章
|
8月前
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
110 0
|
9月前
使用Form报错提示If ngModel is used within a form tag, either the name attribute must be set or the form
使用Form报错提示If ngModel is used within a form tag, either the name attribute must be set or the form
Fullpage.js version 3 has changed its license to GPLv3 and it requires a `licenseKey` option ...
Fullpage.js version 3 has changed its license to GPLv3 and it requires a `licenseKey` option ...
183 0
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
|
小程序
【微信小程序】tabbar报错Component is not found in path “custom-tab-bar/index“
【微信小程序】tabbar报错Component is not found in path “custom-tab-bar/index“
441 0
|
Linux
解决办法:error: <item> inner element must either be a resource reference or empty.
解决办法:error: <item> inner element must either be a resource reference or empty.
247 0
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as t
vue.js报错如下: - Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as , as they will not be parsed.
5678 1

热门文章

最新文章