加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – TextBox在使用TextMode Number回发后丢失了值

发布时间:2020-12-16 06:27:58 所属栏目:asp.Net 来源:网络整理
导读:有奇怪的问题.我有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="confi
有奇怪的问题.我有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>

单击按钮后我尝试获取TextBox值:

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

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

解决方法

它是 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读