简体   繁体   中英

Textbox textchange didn't work in asp.net c#

I have TextBox in my popup page, what i need to do, is to check if the TextBox in the popup contains text for example TextBox.Text.Equals("Admin");

here is the TextBox definition:

<asp:TextBox ID="TextBox1" runat="server" Height="35px" 
      ontextchanged="TextBox1_TextChanged" AutoPostBack="true"
      style="text-align: right; font-size: x-large" Width="200px">
</asp:TextBox>

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    if(TextBox1.Text.Equals("Admin"))
    {
        Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();");
    }
}

the function of TextBox1_TextChanged didn't fetch when the text is changed.

what i need to do, is to close the window when some text is entered, can anyone help me and/or suggest any other solution to solve this problem ? I dont need to press any button to close the window

(the text will be entered to the textbox using card reader and because of that i need to close it without any button click)

thank you so much

I think the text changed event should be handled client side. The text is a very volatile value, imagine what would it mean to go to server side whenever you press a key. The performance would be very bad.

The TextChanged Event of textbox is fired only when you change the content of the textbox and move the cursor out of the control. If your text is entered to the textbox by card reader the cursor will remain inside the textbox. After entering the text try clicking outside the textbox or press Enter or Tab and check your TextChanged Event is fired or not. if the event fired, make sure that textbox text is not cleared in your Page_Load event. You know the use of IsPostBack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM