使用TextMode Number回发后,TextBox失去价值 [英] TextBox loses value after post back with TextMode Number

查看:85
本文介绍了使用TextMode Number回发后,TextBox失去价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有奇怪的问题.我有一个带有 TextBox :

Got weird problem. I have simple page with TextBox:

<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:TextBox ID="amountTextBox" runat="server" TextMode="Number" />
        <asp:Button runat="server" Text="Confirm" OnClick="confirmButton_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

单击 Button 后,我尝试获取 TextBox 值:

After Button click I try to get TextBox value:

public partial class test : Page {
    protected void confirmButton_Click(object sender, EventArgs e) {
        var answer = amountTextBox.Text;
    }
}

但是它是空的.如果删除 UpdatePanel ,则可以获取该值.如果我离开 UpdatePanel 并删除 TextMode 属性,那么我将设法获得该值.但是为什么不能在 UpdatePanel 中将 TextMode 设置为 Number TextBoxt ?

but it's empty. If I remove UpdatePanel, I manage to get the value. If I leave UpdatePanel and remove TextMode property, I manage to get the value. But why can't I have TextBoxt with TextMode set to Number in UpdatePanel?

推荐答案

它是

It is a known issue, a fix is available in .NET 4.5 RTM.

说明

HTML5的输入标签具有新类型,例如type ="number",即需要使手机显示数字键盘而不是数字键盘文字键盘.当对页面进行完整的回发时,它可以在所有页面中正常工作浏览器.但是,如果我将它们放在网站上的更新面板中,部分回发,那么不包含任何新的HTML输入类型从那些浏览器向服务器发回的响应中了解这些新类型(Safari/WebKit和Opera).有用在IE8和Firefox 4中正确显示,但可能仅是因为它们具有没有实现这些新类型,而是退回去理解它一个type ="text"字段.

HTML5 has new types for the input tag, such as type="number", which is needed to make mobile phones display a numerical keyboard instead of a text keyboard. When doing a full postback of the page it works in all browsers. But if I puts these in an updatepanel on a website to do a partical postback, then none of the new HTML input types are included in the postback response to the server from those browsers that understands these new types (Safari/WebKit and Opera). It works correctly in IE8 and Firefox 4, but probably only because they have not implemented these new types and falls back to understanding it as a type="text" field.

这是此问题和解决方法的另一个问题: UpdatePanel输入类型不是html5中的文本.

Here is another question with this issue and workarounds: UpdatePanel with input type other than text in html5.

这篇关于使用TextMode Number回发后,TextBox失去价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆