Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to set Tab Order on WebForms
Message
 
To
05/06/2005 15:15:38
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 1.1
OS:
Windows 2000 SP4
Database:
MS SQL Server
Miscellaneous
Thread ID:
01020349
Message ID:
01020611
Views:
19
>VS.NET 2003
>
>When you make changes to a form - add controls, revise its layout etc. several problems come up:
>
>1. The generated HTML gets nasty-looking - control tags run on one after another without line breaks etc. Are there any global settings that control that kind of thing?

No but it sounds you're using grid layout. I would advise not to use that as it's using absolute positioning with DHTML that won't work in downlevel browsers and as you've found out VS.NET can really screw up the layout for you.

>
>2. The tab order depends (by default) on the control order in the HTML. Is there any way to get VS to do the grunt work of moving controls around in the HTML so the tab order is what I want?

Tab order is not a concept supported by HTML. Controls are rendered top down - since there's no 'absolute' positioning in flow layout there's also no concept of tab order.


>3. Is there any way to set the "focus" on a form to a given control, rather than the browser's address bar?

It takes only a little bit of JavaScript to do this:
<body onload="document.getElementById('txtCompany').focus()">
I have a property on my base Web Form class called FocusedControl I can set. This is handled in the base class like this:
/// <summary>
/// Overriden to handle the FocusedControl property.
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
	if (this.FocusedControl != null) 
		this.RegisterStartupScript("FocusedControl",
"<script language='javascript'>\r\ndocument.getElementById('" + 
this.FocusedControl.ID + "').focus();\r\n</script>\r\n");

	base.OnPreRender (e);
} 
This generically injects the script code into the page and it's as easy as picking the FocusedControl from the designer at design time.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Reply
Map
View

Click here to load this message in the networking platform