NB! This code is IE only
This code is better:
http://www.dotnetbips.com/displayarticle.aspx?id=106
I'm trying to translate it into C#. Could you help me?
This is what i've done so far. Need help on the while loop:
public static void SetInitialFocus2(Control ctrl)
{
StringBuilder s = new StringBuilder();
s.Append("<SCRIPT LANGUAGE='JavaScript'>");
s.Append("function SetInitialFocus()");
s.Append("{");
s.Append(" document.");
Control p = ctrl.Parent;
while (Not typeof p Is System.Web.UI.HtmlControls.HtmlForm)
{
p = p.Parent;
}
s.Append(p.ClientID);
s.Append("['");
s.Append(ctrl.UniqueID);
s.Append("'].focus();");
s.Append("}");
s.Append("window.onload = SetInitialFocus;");
s.Append("</SCRIPT>");
ctrl.Page.RegisterClientScriptBlock("InitialFocus" , s.ToString());
}
"Eirik Eldorsen" <ku*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Check out this code:
http://www.csharphelp.com/archives/archive201.html
"Rob Shorney" <Bi****@community.nospam> wrote in message
news:46**********************************@microsof t.com... Hi,
I have a number of text boxes on my web form. when the text is change the
serverside event TextChanged gets raised and I do some server side
validation. This is fine.
However, when the event has finished processing, I would expect focus to
be
returned to the next textbox on the page - this does not happen.
My question is, how can I programatically in code behind set focus to a
specfied control.
--
Regards
Rob