Make label invisible when textbox empty

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello -

I have a page that runs a stored procedure checking for the existence of a
name in a database. If it exists, lblMessage returns text indicating same.

When a user goes back and clears the textbox, I would like the message to
disappear, instead of waiting for a return trip to the server.

Any suggestions will be greatly appreciated!
 
Sandy,

Setup a client side onchange event for the textbox. In the event check if
the textbox is empty and hide the label.

The javascript event handler will look like this:

function onchange(){
if (myTextBox.value == "") myLabel.style.display="hidden";}

Eliyahu
 
Hi Eliyahu!

Thanks for your response. I am having trouble hooking it up. I put the
script in the html and tried:
<asp:textbox id=txtUserName ontextchanged="onchange" runat="server"
Width="100%"></asp:textbox>

I need to connect it with something in the vb code though, don't I?
 
Sandy,

ontextchanged is a server-side event. You need the client side onchange one.
That is:

<asp:textbox id=txtUserName onchange="onchange();" runat="server"
Width="100%"></asp:textbox>

vb code is on the server side. Your task is a client-side one. In ASP.NET
You need to have clear understanding what belongs to server and what to
client.

Eliyahu
 

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

Back
Top