Textbox text change

M

Mariame

Hi everyone
i have a textbox that is added dynamically in form load
i want an event to happen when the text change
how can i do it?
Thx in Adv
 
J

Joyjit Mukherjee

Hi,

Raise an event in the TextBox_TextChanged event and write appropriate
handlers for that.

regards
Joyjit
 
M

Mariame

the dynamic textbox called "we1"
when i write
Private Sub we1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles we1.TextChanged

End Sub

it gives me error "Handles clause requires a WithEvents variable."

Any idea?
 
F

Franck Quintana

Hi,

Declare your variable using:

WithEvents we1 as System.Web.UI.WebControls.TextBox

Regards,
Franck Quintana
Active+ Software
http://www.activeplus.com

| the dynamic textbox called "we1"
| when i write
| Private Sub we1_TextChanged(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles we1.TextChanged
|
| End Sub
|
| it gives me error "Handles clause requires a WithEvents variable."
|
| Any idea?
|
 
K

Ken Cox [Microsoft MVP]

Hi Mariame,

Are you adding your own handler? Here's some code to show how it is done.
Note that getting the TextChanged event to fire can be tricky... you may
need to hit the Enter key in the texbox after changing the text.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtbx As New TextBox
txtbx.ID = "Mytextbox"
txtbx.Text = "Change this text and hit Enter"
txtbx.EnableViewState = True
PlaceHolder1.Controls.Add(txtbx)
AddHandler txtbx.TextChanged, AddressOf TextBox_TextChanged
End Sub

Private Sub TextBox_TextChanged _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim txtbx As TextBox
txtbx = sender
Label1.Text = txtbx.ID & " at " & Now.ToLongTimeString
End Sub

<form id="Form1" method="post" runat="server">
<p>
<asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder>
<asp:label id="Label1" runat="server"></asp:label></p>
<p>&nbsp;</p>
</form>

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top