setting the focus to a textbox in a user control

G

Guest

Hi,

I have a question. I have created a user control which contains a
textbox and a button. we will enter some search word in the textbox and hit
the button. Then we will get a pop-up with the listbox that contains the
matches. Once I select one of the matches, it will close the pop-up and
display the selected one in a label control which is also in the user
control. Everything is working fine. But I am not getting one thing. After
the pop-up is closed by selecting the match, I would like to set the focus
back to the textbox. But I am not knowing how to do that. I wrote javascript
that will set the focus on onLoad event of <body> of the form. It is working
when the form is first displayed. But when we come from the pop-up it is not
setting the focus. I am not knowing where exactly I should set the focus.
Please let me how to do it.

Thanks,
Sridhar.
 
T

Ton Strankinga

Dear Sridhar,

Maybe use this

protected void setFocus( System.Web.UI.Control ctrl )

{

string s = "<SCRIPT language='javascript'>document.getElementById('" +
ctrl.ID + "').focus() </SCRIPT>";

this.RegisterStartupScript( "focus", s );

}

In the on load event

this.setFocus( TextBox1 );



Regards,

Ton
 

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,012
Latest member
RoxanneDzm

Latest Threads

Top