473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

TextBox.Focus not working in FormView

Hi

The client script does not get created when calling the Focus method on the
TextBox. No errors occur. What am I doing wrong please?

protected void fv_Load(object sender, EventArgs e)
{
FormView fv = (FormView)sender;
TextBox tbFirstName = (TextBox)fv.FindControl("tbFirstName");
tbFirstName.Focus();
}

Thanks
Andrew

Mar 15 '07 #1
2 6270
"J055" <j0**@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
The client script does not get created when calling the Focus method on
the TextBox. No errors occur. What am I doing wrong please?

protected void fv_Load(object sender, EventArgs e)
{
FormView fv = (FormView)sender;
TextBox tbFirstName = (TextBox)fv.FindControl("tbFirstName");
tbFirstName.Focus();
}
What happens if you rem out the first two lines within the method...?

Alternatively, what happens if you put the third line of the method in
Page_Load()...?
Mar 15 '07 #2
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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: shariffshiraz | last post by:
I am using a FormView, Insert Template. I have 3 textboxes which are bound. I would like to use a default (static) value in one of the textboxes. Here's the (relevant) sample code: ...
4
by: Luqman | last post by:
How can I display any field value in textbox of sqldatasource using VS.Net 2005 ? Say : Dim x as new AccessDataSource X.connectionstring="Data source="D:\mydb.mdb" X.Selectcommand="Select...
2
by: Sridhar | last post by:
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...
9
by: Dick | last post by:
How do I set the focus to a control that is a child to a FormView? I've tried the obvious (below) and lots of variations but none seam to work! Sub Page_Load(ByVal sender As Object, ByVal e As...
5
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if...
5
by: Ken Varn | last post by:
I have just started using VS.NET 2005 after using VS.NET 2003. One of the things that I noticed is that in ASP.NET, the DataSource property for TextBoxes and other web controls is no longer...
0
by: Paul | last post by:
I have a web form with a FormView that will display data based on an entry in the TextBox. I want to add a second FormView to work with a second TextBox. However, when I add the second TextBox,...
0
by: trint | last post by:
I have several GridViews that call a fuction, when clicked, called "getSelected". The very last thing I want getSelected to do is to SetFocus on a FormView (FormView1). Here is how I have this...
9
by: David C | last post by:
I have an asp.net page that contains a FormView with several controls bound to a SqlDataSource. One of the controls is a TextBox bound to a date column. I have the following additional properties...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.