TEL:150-0382-3679
新闻资讯 News Center
建站知识 / 公司动态
使用伪静态或者地址重写后,页面事件回发

地址重写后,来一个按钮事件,页面地址马上返回原形,解决这个问题的方法是:
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Web.UI;

namespace GB
{
    /// <summary>
    ///NewForm 的摘要说明
    /// </summary>
    public class NewForm : Page
    {
        public NewForm()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        protected override void Render(HtmlTextWriter writer)
        {
            if (writer is System.Web.UI.Html32TextWriter)
            {
                writer = new FormFixerHtml32TextWriter(writer.InnerWriter);
            }
            else
            {
                writer = new FormFixerHtmlTextWriter(writer.InnerWriter);
            }
            base.Render(writer);
        }
    }

    internal class FormFixerHtml32TextWriter : System.Web.UI.Html32TextWriter
    {
        private string _url; // 假的URL
        internal FormFixerHtml32TextWriter(TextWriter writer)
            : base(writer)
        {
            _url = HttpContext.Current.Request.RawUrl;
        }
        public override void WriteAttribute(string name, string value, bool encode)
        {
            if (_url != null && string.Compare(name, "action", true) == 0)
            {
                value = _url;
            }
            base.WriteAttribute(name, value, encode);
        }
    }
    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)
        {
            if (_url != null && string.Compare(name, "action", true) == 0)
            {
                value = _url;
            }
            base.WriteAttribute(name, value, encode);
        }

    }
}
定义上面的类,在有使用页面按钮事件的页面,
public partial class Default: System.Web.UI.Page
改为:
public partial class Default: GB.NewForm

一站式全网营销,您身边的网络营销顾问,为您一对一私人定制符合您实际需求的网络营销实施方案!
24小时咨询热线:
150-0382-3679