[karsten samaschke]

ASP.NET daily. Or weekly.

April 2003 - Posts

How to add Intellisense-support for your custom controls to VS.NET

Today I found an interesting link about how to extend the Visual Studio .NET and its support for IntelliSense on your own Controls.

Take a look at the article published here: http://www.wdvl.com/Authoring/ASP/NET_Nutshell/asp_net3_3.html

How to access values of dynamically created TextBoxes

If one adds controls dynamically to a page and wants to get their information after PostBack, one needs to recreate these elements after the PostBack. Let's consider the following idea: First you create some controls:

   for(int i=0;i<10;i++) {
      TextBox objBox = new TextBox();
      objBox.ID = "objBox" + i.ToString();
      this.Page.Controls.Add(objBox);
   }

After PostBack, you want to retrieve the text entered in the third TextBox. If you try this:

   String strText = objBox2.Text;

you'll receive an exception. Why? Because the boxes have not been created again and the local variable objBox2 simply not exists.

How to retrieve the Box?

You'll need to recreate the box by using the code above. Then, you may try to get its value by using the following code:

   TextBox objBox2;
   objBox2 = this.Page.FindControl("objBox2") as TextBox;
   if(objBox2 != null)
      Response.Write(objBox2.Text);

Try it and take a look at the result. Did it work well for you?

Sorry about the long interval between updates

I'm really sorry for not updating this page for more than two months. It wasn't because of loosing interest in this weblog - it was just because of time: Right now I'm working on my second book (and the third one will come soon, too), so it is really hard to put a focus on this weblog.

So, if you want me to continue this weblog, please give me feedback on interesting topics and on things I should write about. I will use this feedback for writing new articles.

Another thing: Please feel free to contact me via info@ksamaschke.de if you are interested in my knowledge. I may work for you as programmer, as speaker on conferences, as trainer on ASP and ASP.NET and as writer of articles or books.

Thanks for your interest so far!

SmartNavigation and why not to use it

SmartNavigation seems to be a nice feature - it allows Internet Explorer to handle PostBacks in a very clever way. You don't have to worry about having a long site - it will return to the point where you have been before. Or if you define some events - SmartNavigation will enable you to invoke the handlers without posting the page back to the server.

But: If you are going to program a serious website for users of different browsers (Netscape, Opera, Konqueror or Safari) you need to turn SmartNavigation off, because it simply doesn't work with this kind of browsers.

Another aspect is the following behaviour reported in the newsgroups (and not verified by myself ;): If you would like to put the focus on some objects of your page (i.e. textboxes), you usually use JavaScript:

   Page.RegisterClientScriptBlock("focus", _
     "document.<id-of-your-control>.focus();")

or (VB.NET)

   Page.RegisterClientScriptBlock("focus", _
      "<script language=""JavaScript"">" & _
         "document.<id-of-your-control>.focus();" & _
      "</script> ")

But: Try it with SmartNavigation turned on: It simpy won't work on some systems. The reasons are unknown, but it seems to be, as if IE won't interpret the script correctly.

Sad, isn't it?

More Posts