遇到奇怪的问题。我有一个简单的页面 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)。但为什么我不能拥有 TextBoxt
与 TextMode
设置为 Number
在 UpdatePanel
?
最佳答案
是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/