By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,856 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,856 IT Pros & Developers. It's quick & easy.

setting the focus to a textbox in a user control

P: n/a
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.
Feb 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DWS
Srid,

After you set label call the focus method on the textbox.
Good Luck
DWS

"Sridhar" wrote:
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.

Feb 10 '06 #2

P: n/a
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



"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:55**********************************@microsof t.com...
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.

Feb 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.