TextBox TextChanged property

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I have an asp.net page that contains a FormView with several controls bound
to a SqlDataSource. One of the controls is a TextBox bound to a date
column. I have the following additional properties on the TextBox:

OnTextChanged="txtDestroyed_TextChanged" AutoPostBack="true"

I expected the OnTextChanged event to fire immediately and run the postback
but it does not. The code does not run until I click the "Update" button.
Can anyone help? Below is the event code. Thanks.

Protected Sub txtDestroyed_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
'Run function to delete all documents in all subfile folders for
this file
Dim strText As String
strText = DBClass.DeleteFileDocuments(txtFileNumber.Text)
txtMsg.Text = strText

Try

' Use the UpdateItem method to programmatically update
' the current record in the FormView control.
fvFileCase.UpdateItem(True)

Catch ex As HttpException

txtMsg.Text = strText & "<br />The FormView control must be in
edit mode to update a record."

End Try
End Sub

David
 
I can only assume this is by design. It would be horribly inefficient and
confusing to the user to have the page post back in response to each key
pressed. In addition, I can't really tell but it appears you are deleting
files based on the current text? How does that work if the text changes but
the user is not yet done typing the correct name?

Depending on exactly why you want this, it is probably a job for client-side
javascript and possibly AJAX.
 
I have a javascript prompt to make sure they want to do this. If ok, then
the idea is to remove all document files for that file number. Should I put
the code into the Updating event of the SqlDataSource or ??? instead?
Thanks.

David
 
I'm still not clear on how you know they've finished typing. If they've only
typed part of the name, it seems that you could end up deleting the wrong
files.

In this case, a button seems required to indicate they want to submit the
change. Otherwise, I don't see how you can know when they've finished
typing.
 
I thought that the TextChanged event only fired when they leave the control.
Besides, it is a date field with a validator so they cannot type half of a
date.

David
 
Okay, I'm with you now. You are saying that's what you want but it doesn't
do that?

I just tried it in VS2008, Vista, and IE7 and it *does* postback when I tab
away from the textbox. So I don't know what is different for you. You said
you have some javascript to confirm. Is it possible that is interfering
somehow?
 
I have added an onchange event as follows:

Attributes.Add("onchange", "return ConfirmDestroy();")

The javascript function is being called below:

function ConfirmDestroy()
{
return confirm('Are you sure you want to mark file ' + varfileno + ' as
destroyed? NOTE: This will delete all documents in all subfile folders.');
}

I want to be able to cancel and not do the postback, thus the confirm.

David
 
One more thing I noticed. It works if I remove the javascript but the
formview updateitem is failing and I don't know why. I really want to save
the changes when they confirm. Thanks.

David
 
I'm not 100% certain what is happening off the top of my head, but the
postback is accomplished using javascript. I think your javascript is
overriding ASP.NET's javascript and that's why it doesn't happen.
 
hi guys,

i have a registration form. in the text changed event of a text box im checking whether the username entered by the user is existing or not. If i press tab or if i go for a next control text changed event is firing. but if i change the text and directly go and click a button the pae post backs and text changed event is firing but the button click event is not firing.

can anyone help me

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng
 
i assume you have autopostback set on the textbox and are talking about
server events. there is only one postback event per postback. having the
textbox force a postback causes its postback to occur before the button
postback is triggered.


autopostback is seldom a very good design. you should look at removing it.

-- bruce (sqlwork.com)
 
Back
Top