在html5中输入类型不是文本的UpdatePanel

Maz*_*eri 10 asp.net html5 updatepanel scriptmanager

我正在开发一个使用ASP.NET渲染HTML5的开源项目.在这里你可以看看:http: //asphtml5.codeplex.com/

现在我在更新面板时遇到问题,回复了"text"以外的类型的输入值.你可能知道,html 5引入了几种输入类型,例如'number','tel','search'等.现在,如果我渲染这样的控件,一切正常情况下工作正常,但如果我把它们放入UpdatePanel,没有值将被回发,值将被重置.

这是一小段产生相同错误的代码:

    <asp:UpdatePanel runat="server" ID="UP">
        <ContentTemplate>
            <p>
                Enter A Number:
                <asp:TextBox runat="server" ID="Number2" type="number" />
            </p>
            <asp:Button Text="Submit" runat="server" ID="BtnSubmit" OnClick="BtnSubmit_Click" />
            <p>
                You entered :
                <asp:Label Text="" ID="LblValue" runat="server" />
            </p>
        </ContentTemplate>
    </asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)

如果您在支持html 5的浏览器上测试此代码,请以Chrome为例,将显示Numeric Up-Down字段.但是如果单击提交按钮,它将丢失您输入的值.

这是事件处理程序的代码:

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            LblValue.Text = Number2.Text;
        }
Run Code Online (Sandbox Code Playgroud)

我已经尝试过的是读取UpdatePanel,ScriptManager和ScriptManagerProxy类代码,没有找到.

我想我可能需要创建自己的UpdatePanel和/或ScriptManager类来使用.

任何人都可以帮助我,并告诉我在哪里检查.

Maz*_*eri 2

好吧,我想出了一个办法来解决这个问题。首先我发现Tim Medora提供的代码有问题。这都是this.修改器的错。所以这个 JavaScript 解决了这个问题:

var _textTypes = /^(text|password|hidden|search|tel|url|email|number|range|color|datetime|date|month|week|time|datetime-local)$/i;
function Sys$WebForms$PageRequestManager$_onFormSubmit(evt) {
...
if (_textTypes.test(type) ||
       (((type === 'checkbox') || (type === 'radio')) && element.checked)) {
       formBody.append(encodeURIComponent(name));
       formBody.append('=');
       formBody.append(encodeURIComponent(element.value));
       formBody.append('&');
...
}
Run Code Online (Sandbox Code Playgroud)

现在我必须将我的函数注入到ScriptResource.axd. 目前我找到了一种似乎有效的方法:

我创建了一个在命名空间 DotM.Html5.Handlers 中ScriptResouceHandler扩展的类System.Web.Handlers.ScriptResourceHandler

在其中ProcessRequest我打电话base.ProcessRequest(context)去做它的工作。但我想将我的函数添加到一个渲染原始函数中。我发现是加密ZSystem.Web.Extensions,4.0.0.0,,31bf3856ad364e35|MicrosoftAjaxWebForms.debug.js|通过的时候。

另一个问题是System.Web.Handlers.ScriptResourceHandler,在内部调用“Page.DecryptString”方法来解密查询字符串参数。所以我无法通过反射调用该方法。

这是代码:

        protected sealed override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);
            if (CypherContainsAjax(context.Request.QueryString["d"]))
                context.Response.Write(OnFormSubmit);
        }

        private bool CypherContainsAjax(string cypher)
        {
            var text = DecryptString(cypher);
            if (text == null)
                return true; //Then Add it everywhere. What else could I do? :D
            return text.Contains("MicrosoftAjaxWebForms");
        }

        private string DecryptString(string cypher)
        {
            if (PageDecryptString == null)
                return null;
            return (string)PageDecryptString.Invoke(null, new object[] { cypher });
        }
        private static MethodInfo PageDecryptString;
        static ScriptResourceHandler()
        {
            PageDecryptString = typeof(Page).GetMethod("DecryptString", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
        }
Run Code Online (Sandbox Code Playgroud)

你可以称之为某种丑陋的黑客攻击......