Thursday, March 22, 2012

setting the focus to a textbox in a user control

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
"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 hi
t
> 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 javascri
pt
> that will set the focus on onLoad event of <body> of the form. It is worki
ng
> when the form is first displayed. But when we come from the pop-up it is n
ot
> setting the focus. I am not knowing where exactly I should set the focus.
> Please let me how to do it.
> Thanks,
> Sridhar.
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" <Sridhar@.discussions.microsoft.com> wrote in message
news:552882B9-23EA-478D-9ACE-1B7F75494933@.microsoft.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.

0 comments:

Post a Comment