473,386 Members | 1,609 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,386 software developers and data experts.

Setting focus on control in webform

I have a webform and found some code where I understand some of it, but not
all
The code is as follows
public static void SetFocus(Control control)
{
StringBuilder sb = new StringBuilder();

sb.Append("\r\n<script language='JavaScript'>\r\n");
sb.Append("<!--\r\n");
sb.Append("function SetFocus()\r\n");
sb.Append("{\r\n");
sb.Append("\tdocument.");

Control p = control.Parent;
while (!(p is System.Web.UI.HtmlControls.HtmlForm)) p = p.Parent;

sb.Append(p.ClientID);
sb.Append("['");
sb.Append(control.UniqueID);
sb.Append("'].focus();\r\n");
sb.Append("}\r\n");
sb.Append("window.onload = SetFocus;\r\n");
sb.Append("// -->\r\n");
sb.Append("</script>");

control.Page.RegisterClientScriptBlock("SetFocus", sb.ToString());
}
The code results in adding Javascript to your page as follows:
<script language='JavaScript'>
<!--
function SetFocus()
{
document.Form1['TextBox1'].focus();
}
window.onload = SetFocus;
// -->
</script>
But you don't need to care about that because all you need to do to use it
is call your static method from your code behind class:
PageUtility.SetFocus(TextBox1);I have converted it to VB. What I don't
understand is the last one sentence with the first word PageUtilityWhat is
it for?regardsreidarT
Nov 21 '05 #1
1 1775
I found the solution myself. PageUtility means only Me
Sorry for the inconvenience.
regards
reidarT
"reidarT" <re****@eivon.no> skrev i melding
news:%2****************@TK2MSFTNGP14.phx.gbl...
I have a webform and found some code where I understand some of it, but not
all
The code is as follows
public static void SetFocus(Control control)
{
StringBuilder sb = new StringBuilder();

sb.Append("\r\n<script language='JavaScript'>\r\n");
sb.Append("<!--\r\n");
sb.Append("function SetFocus()\r\n");
sb.Append("{\r\n");
sb.Append("\tdocument.");

Control p = control.Parent;
while (!(p is System.Web.UI.HtmlControls.HtmlForm)) p = p.Parent;

sb.Append(p.ClientID);
sb.Append("['");
sb.Append(control.UniqueID);
sb.Append("'].focus();\r\n");
sb.Append("}\r\n");
sb.Append("window.onload = SetFocus;\r\n");
sb.Append("// -->\r\n");
sb.Append("</script>");

control.Page.RegisterClientScriptBlock("SetFocus", sb.ToString());
}
The code results in adding Javascript to your page as follows:
<script language='JavaScript'>
<!--
function SetFocus()
{
document.Form1['TextBox1'].focus();
}
window.onload = SetFocus;
// -->
</script>
But you don't need to care about that because all you need to do to use it
is call your static method from your code behind class:
PageUtility.SetFocus(TextBox1);I have converted it to VB. What I don't
understand is the last one sentence with the first word PageUtilityWhat is
it for?regardsreidarT

Nov 21 '05 #2

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

Similar topics

2
by: Sean | last post by:
hi, i have a webform, which has a couple of formfields including a couple of buttons too. the webform structure is textbox1 button1 button2 textbox2 button3 - submit
2
by: David Cho | last post by:
After the user fills out the webform, my customer would like a default button on the form to have focus, so that all the user has to do is press <enter> as opposed to having to take the cursor and...
2
by: Mike | last post by:
Hi, I have a webform with two textboxes and two buttons. I would like to set the focus to the first textbox when the page is displayed. I tried to change the TabIndex, but apparently, it does not...
5
by: Glenn T. Kitchen | last post by:
Hello All, Does anyone know how to set the focus to a textbox control on Page_Load? Thank you, Glenn
2
by: gabriel Morgulis | last post by:
How can I set the focus on a particular control in a webform? IE: If I have 3 textboxs controls on my webform and I want to be on the middleone , how can I do it? I saw that there is a method...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
7
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
5
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
3
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.