简体   繁体   English

如何在TextChanged事件中获取新输入的文本?

[英]How to get the newly entered text in the TextChanged event?

I'm doing a page navigation control. 我正在做页面导航控件。 After typing a new number in text box and Enter, 在文本框中输入新的数字,然后按Enter,

void pageNoTextBox_TextChanged(object sender, EventArgs e)

The above event is called.But I am still getting the old text from the text box in the following statement 上面的事件被称为。但是我仍然从下面的语句中的文本框中获取旧文本

newPageNumber = Int32.Parse(pageNoTextBox.Text.Trim());

for example if the textbox had 1 and and I entered 12 , what I am getting is 1 in the TextChanged event where as javascript returns new value. 例如,如果文本框有1并且我输入12 ,则在TextChanged事件中我得到的是1 ,其中javascript返回了新值。

<asp:TextBox ReadOnly="false" CssClass="txtfld_s"  ForeColor="white" ID="pageNoTextBox" runat="server" Text="" AutoPostBack="true"  CausesValidation="True" OnTextChanged="pageNoTextBox_TextChanged"></asp:TextBox>

This is the text box. 这是文本框。 Is there any way to get the newly entered text using C#? 有什么方法可以使用C#获取新输入的文本吗?

Well I think this will do the thing you want. 好吧,我认为这会做您想要的事情。

private void pageNoTextBox_TextChanged(object sender, EventArgs e)
{
    TextBox textbox = sender as TextBox;
    if(textbox != null)
    {
      string theText = textbox.Text;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Textbox的TextChanged事件中获取旧文本和更改文本框的文本? - How to get old text and changed text of textbox on TextChanged event of textbox? 如何在datagridview textchanged 事件中从当前单元格获取文本? - How to get the text from current cell in datagridview textchanged event? 如何在TextChanged中获取新文本? - How to get the NEW text in TextChanged? 如何使用计时器触发Text.TextChanged事件 - How to fire Text.TextChanged event with timer 从TextChanged事件中的wpf文本框中删除文本 - get deleted text from wpf textbox in TextChanged event 如何使用 TextChanged 事件将字符串附加到 TextBox 中的文本? - How to append a String to a text in TextBox using TextChanged event? 如何在没有 Textchanged 事件的情况下知道文本框的文本更改 - How can I know Text changes for textboxes without Textchanged event TextBox:TextChanged事件 - 输入x字符时自动进行 - TextBox: TextChanged Event - Autovalidating when x chars have been entered 在不触发 TextChanged 事件的情况下更改文本框文本 - Changing Textbox text without firing TextChanged event 如果用户在文本框中键入或者以编程方式调用myTextBox.Text,如何查找是否触发了“TextChanged”事件 - How to find out if the “TextChanged” event is fired if user is typing into a textbox or myTextBox.Text is called programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM