asp.net - 使用 TextMode Number 回发后,TextBox 失去值(value)

标签 asp.net textbox updatepanel

遇到奇怪的问题。我有一个简单的页面 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值(value):
public partial class test : Page {
    protected void confirmButton_Click(object sender, EventArgs e) {
        var answer = amountTextBox.Text;
    }
}

但它是空的。如果我删除 UpdatePanel ,我设法获得了值(value)。如果我离开 UpdatePanel并删除 TextMode属性(property),我设法获得了值(value)。但为什么我不能拥有 TextBoxtTextMode设置为 NumberUpdatePanel ?

最佳答案

a known issue ,.NET 4.5 RTM 中提供了一个修复程序。

描述

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 with input type other than text in html5 .

关于asp.net - 使用 TextMode Number 回发后,TextBox 失去值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23777011/

相关文章:

C#/ASP.NET Oledb - MS Excel 读取 "Unspecified error"

asp.net - 禁用javascript中的复选框并将其识别为在服务器端选中

c# - WPF 更改聚焦的文本框背景颜色

javascript - 更新面板 AsyncPostback 触发器在 IE 中不起作用

asp.net - 基本的 Mono 安装不起作用

asp.net - 在 IIS 7 上调试 500 错误

javascript - 我如何使用 javascript 设置文本框的值

c# - 如何在文本框中使用 double?

javascript - 如何从 JavaScript 更新 UpdatePanel

asp.net - 更新面板不起作用,不知道为什么