Convert Hex Color to System.Drawing.Color in VB.Net

27. March 2009

Here's a simple one....

tcStatusColor.BackColor = System.Drawing.ColorTranslator.FromHtml("#4f81db")

Code Snippets, VB.NET , , ,

Merging DataTables

25. March 2009
   1: Public Sub MergeDataTables(source as DataTable, destination As DataTable)   
   2:   destination.BeginLoadData()   
   3:  
   4:   For i As Integer=0 To source.Rows.Count - 1
   5:     destination.LoadDataRow(source.Rows(i).ItemArray,True)
   6:   Next
   7:  
   8:   destination.EndLoadData()  
   9: End Sub

Reference: by All-Star at http://forums.asp.net/p/1075389/1578419.aspx

Programming, VB.NET , ,

Setting Focus in ASP.Net

24. March 2009

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

ASP.NET, Code Snippets , , ,

Stripping all HTML Characters using VB.Net

23. March 2009

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.

VB.NET