Setting Focus in ASP.Net

Found a great article on setting focus without using Javascript and being able to do it, programmically.

ASP.NET 2.0 simplified this problem and introduce a concept of "default focus". There is a new DefaultFocus attribute that allows you to easily set focus to desired controls. The sample HTML code bellow will set focus on control named textbox1:

<form id="Form1" defaultfocus="textbox" runat="server">
  <asp:textbox id="textbox1" runat="server"/>
  <asp:textbox id="textbox2" runat="server"/>
  <asp:button id="button1" text="Button1" runat="server"/>
</form>

ASP.NET 2.0 provides three different new solutions if you need to set focus dynamically. At run time you can use Page.SetFocus method with control's ID as a parameter or you can simply call a new control's Focus method. They both do practically the same thing. It is only programmer's choice to choose which method likes more.

There is also DefaultFocus property of the form element. Set this property to ID of wanted control, run the project and that control will get focus when page is first time loaded.

   1: pnlLookupDetail.Visible = True
   2: Page.SetFocus(txtLookupDescription)

The Full Article can be found here, http://www.beansoftware.com/asp.net-tutorials/focus-asp.net.aspx

Stripping all HTML Characters using VB.Net

This is actually pretty easy and I had needed to use it on a page where I wanted to use a ToolTip of the contents of an editor which stored the HTML of the content...

Using Regular Expression we can strip off the HTML tags.

   1: Dim ContentDataStrippedOfHTML As StringContentDataStrippedOfHTML = Regex.Replace(SourceOriginalDataStringHere, "<(.|\n)*?>", String.Empty) 
   2:  

Right to the point.