Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Give focus to an asp:textbox control 2

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
I'm using an asp:textbox control on a web form that includes several asp:textbox controls and an asp:button control. No controls initially have the focus. Anyone able to tell me how to give the asp:textbox the focus so the cursor will automatically be blinking in the textbox once the page is loaded?
 
I am running RC1. Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Hi Wayne,

Earlier in this thread we were both wondering about the difference between References and Imports. I've got a little clearer picture of it so I thought I'd share it as best I can.

If you are going to use an assembly (dll) in your project you must add a reference to it. For instance, if you are going to use the OLEDB managed provider for data access then you must add a reference to the System.Data.dll assembly because this assembly contains that managed provider. No "Imports" or in my C# case "using" is required to use the assembly so you don't have to add the "Imports" statements to your code. But if you don't add the "Imports" statement, you'll have to use the full name of each class (namespace.classname) whereas if you do use the "Imports" statement you can simply use the classname.

I plan to prove this to myself by creating an "Imports" statement for the namespace.class used with the SetInitialControl function we are working on. I should then no longer have to reference the namespace.

Pretty cool, huh? Doesn't take much to get me excited. Thanks for all the stuff you guys are sharing!

Kyle


 
Jack and Wayne,

This is going a little far! I had no intension of learning VB.NET. C# rules!!! Just kidding!!!! :)

I'm going to include more in this post that you need to know for the solution to work so I'll tell you up front that I did get it to work.

I loaded Wayne's VB project into VS. First error I got told me I had to create a website at the same location so I used Front Page to create the forums web site and copied Wayne's project into it. I then loaded and compiled the Util project with no errors. I made the reference and got the same results that Wayne got, you could type the assembly name and class but not see the method. In my C# version I define the namespace for the Toolbox class and in your VB version the namespace was not defined so I added that. But that didn't make any difference. It just meant that I now had to type the assemblyname.namespacename.classname but again no method. In VB if you include both the assembly name and namespace you have to refernce both. Of course I had to test how it is in C# and in C# the assembly name is not required. It was odd for me to see the VB code without a namespace defined but I'll get over it. So then I remembered how I had to learn to make the method global in C# using the static keyword so I proceeded to try every C# combination I could in VB only to get one error after another. Luckily, at one of the conferences I attended I was given a VB.NET book that I thought I would never use. In VB.NET to make methods public you use the Shared keyword as in Shared Sub SetInitialFocus(ByVal control As Control). This is the solution that revealed the method in the calling project. So I thought I'd use this to also prove our discussion on "Imports" vs "References". The assembly must be referenced. As an option you can add Imports to define and shorten the path to your methods. In VB this didn't work when namespace was included unless the namespace was included in the Imports statement. It made me type assemblyname.namespace.class.method even when I added "Imports util". So I removed the namespace like the original file that was sent to me. This time when I added "Imports util" at the top of the page I could type toolbox. and see the SetInitialFocus in intellisense. Bottom line, seeing the SetInitialFocus method appear in intellisense is a beautiful thing. Back to C# ... :-0

Kyle

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top