Hi Andrew,
As for setting control focus inside a FormView control, I suggest you the
"PreRender" event, because this is the last event in control's server-side
lifecycle that can use to change control state. Also, in those earlier
event(such as Load), the FormView's content may haven't been fully
configured so our changes on them may bave been overwritten by some other
internal code. Also for "focus" setting, it is also a global setting on
page, maybe some other controls on page will acquire the focus also.
Therefore, I think you can put the code into FormView.PreRender event
handler as below:
================
protected void FormView1_PreRender(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Insert)
{
TextBox txt = FormView1.FindControl("nameTextBox") as TextBox;
if (txt != null)
{
Page.SetFocus(txt);
}
}
}
=======================
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.