OnLeave event on a textbox?

G

Guest

Hi NG,

Can anyone tell me how to create a OnLeave event on a regular textbox in an
ASP.NET webform? The only events I have available are: TextChanged, Disposed,
Init, Load, Prerender and Unload..

Thanks!

regards,

M.L.
 
G

Guest

Hi,

I want to disable another textbox in the same form if the user has entered
anything into the first box. The OnLeave is needed to determine whether this
is true. Like so:

private void TextBox1_OnLeave()
{
if (TextBox1.Text.Length > 0)
TextBox2.Enabled = false;
}

How can this be implemented?

Thanks!
 
G

Guest

Hi,

Thanks very much for the solution, but in fact I would prefer to do it
server-side.. Is this not possible?
 
E

Eliyahu Goldin

You can do it on client side with an onblur event. What do you want to do on
this event?

Eliyahu
 
E

Eliyahu Goldin

<asp:textbox id=TextBox1 ...
onblur="document.getElementById('TextBox2').disabled=(this.value=='')" ...

<asp:textbox id=TextBox2 ...

No server-side code is required.

Eliyahu
 
E

Eliyahu Goldin

If the user enters something, you will get a server-side TextChanged event.
Is not it good for you?

Eliyahu
 
M

Marina

No. This event happens on the client in the browser. The server is on the
othe rend of the wire - it has no idea that the user switched focus to a
different field.

You can trigger a postback to the server - but you would still need client
side code to trigger this. And then your page looks ugly because it keeps
flashing.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top