setting the focus to a textbox in a user control

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Srid,

After you set label call the focus method on the textbox.
Good Luck
DWS
 
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

Back
Top