Ask a Question related to ASP.NET General, Design and Development.
-
Marco Liedekerken #1
Which control had focus before postback?
Hi,
Is it possible to retrieve the control that had the focus when the page was
posted back?
Because the focus is lost when a postback occurs I want to manually set the
focus to the control that previously had the focus (smartnavigation doesn't
do the trick).
Thanks, Marco
Marco Liedekerken Guest
-
Taking focus from a control
In my app, I have a DataGrid, and when a row is double-clicked, a new view is put up showing the data. I also add eventListeners to the stage for... -
Setting Focus in a User Control
I have an editable datagrid as part of a usercontrol. When I click the Edit button, I wish for focus to be set on the first control, a... -
How control which button has focus [ENTER]
Hello, I'm facing a problem with the behavior of the key while editing items in a datagrid. I would like to make sure that the cancel button is... -
focus/lost focus of custom control
Hi new to .NET and have a question. What I want to do if have a custome control (contains a table grid of text boxes) and multiple instances... -
Control focus
Hi guys, How to Focus a TextBox on page load? I have this function: public static void FocusControl(Page pagina, WebControl control) {... -
Kairi Zikpin #2
Re: Which control had focus before postback?
use javascript
once the page hits the browser, .net is no longer at play
eg, object.onfocus(), set some hidden field to the control's name
once the page is back to the browser, use javascript again to set focus
it's a lot of work but that's the only way i've found that works. just
be careful about objects no longer being on the form or being disabled.
Marco Liedekerken wrote:> Hi,
>
> Is it possible to retrieve the control that had the focus when the page was
> posted back?
>
> Because the focus is lost when a postback occurs I want to manually set the
> focus to the control that previously had the focus (smartnavigation doesn't
> do the trick).
>
> Thanks, Marco
>
>Kairi Zikpin Guest
-
Jeff Siver #3
Re: Which control had focus before postback?
Here's a C# function you can call to have a page set focus when the page is
displayed:
protected void SetFocus(WebControl wc)
{
StringBuilder sScript = new StringBuilder("");
sScript.Append("<script language='javascript'>");
sScript.Append(" document.getElementById('" + wc.UniqueID + "').focus()");
sScript.Append("</script>");
Page.RegisterStartupScript("Focus", sScript.ToString());
}
All you need to do is call this function before posting the page. Should do
what you need.
"Kairi Zikpin" <zikkai.nospam.@netscape.net> wrote in message
news:3F0199E1.1070105@netscape.net...was> use javascript
> once the page hits the browser, .net is no longer at play
>
> eg, object.onfocus(), set some hidden field to the control's name
> once the page is back to the browser, use javascript again to set focus
>
> it's a lot of work but that's the only way i've found that works. just
> be careful about objects no longer being on the form or being disabled.
>
> Marco Liedekerken wrote:> > Hi,
> >
> > Is it possible to retrieve the control that had the focus when the pagethe> > posted back?
> >
> > Because the focus is lost when a postback occurs I want to manually setdoesn't> > focus to the control that previously had the focus (smartnavigation>> > do the trick).
> >
> > Thanks, Marco
> >
> >
Jeff Siver Guest



Reply With Quote

