473,769 Members | 7,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Contro l control)
{
StringBuilder sb = new StringBuilder() ;

sb.Append("\r\n <script language='JavaS cript'>\r\n");
sb.Append("<!--\r\n");
sb.Append("func tion SetFocus()\r\n" );
sb.Append("{\r\ n");
sb.Append("\tdo cument.");

Control p = control.Parent;
while (!(p is System.Web.UI.H tmlControls.Htm lForm)) p = p.Parent;

sb.Append(p.Cli entID);
sb.Append("['");
sb.Append(contr ol.UniqueID);
sb.Append("'].focus();\r\n") ;
sb.Append("}\r\ n");
sb.Append("wind ow.onload = SetFocus;\r\n") ;
sb.Append("// -->\r\n");
sb.Append("</script>");

control.Page.Re gisterClientScr iptBlock("SetFo cus", sb.ToString());
}
The code results in adding Javascript to your page as follows:
<script language='JavaS cript'>
<!--
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.Set Focus(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?regardsreid arT
Nov 21 '05 #1
1 1790
I found the solution myself. PageUtility means only Me
Sorry for the inconvenience.
regards
reidarT
"reidarT" <re****@eivon.n o> skrev i melding
news:%2******** ********@TK2MSF TNGP14.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(Contro l control)
{
StringBuilder sb = new StringBuilder() ;

sb.Append("\r\n <script language='JavaS cript'>\r\n");
sb.Append("<!--\r\n");
sb.Append("func tion SetFocus()\r\n" );
sb.Append("{\r\ n");
sb.Append("\tdo cument.");

Control p = control.Parent;
while (!(p is System.Web.UI.H tmlControls.Htm lForm)) p = p.Parent;

sb.Append(p.Cli entID);
sb.Append("['");
sb.Append(contr ol.UniqueID);
sb.Append("'].focus();\r\n") ;
sb.Append("}\r\ n");
sb.Append("wind ow.onload = SetFocus;\r\n") ;
sb.Append("// -->\r\n");
sb.Append("</script>");

control.Page.Re gisterClientScr iptBlock("SetFo cus", sb.ToString());
}
The code results in adding Javascript to your page as follows:
<script language='JavaS cript'>
<!--
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.Set Focus(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?regardsreid arT

Nov 21 '05 #2

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

Similar topics

2
3219
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
1009
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 click. The problem is that I have buttons in a user control (its a navigation control) across the top of the page. So the button in the left upper corner always has focus, and that is not the button that the customer wants focused. Is there...
2
1070
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 have any effect. Any idea on how I could do that? Thanks Mike
5
1365
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
2271
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 called focus, that it would replace the .setfocus method of VB6. But I don't understand the example. Does anyone have an example ?
1
2062
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 for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
7
8063
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 when the form is loaded. The textbox cannot be the first in the Tab order, since it's not at the top of the window, and it seems silly to start the tab order at it just to fix this issue. I cannot call control.Focus() from Form1_Load() since...
5
2040
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 information and one that resets the form... The second on, the reset button, i would like to set focus back to the first textbox on the form. I already have an onload in my body, which sets the
3
2166
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 try setting focus but something seems to set the focus back to the control which had it before validation. Any ideas? TIA, KK
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.