How to read the comma separated values from a string

VB.NET Dim myString As String = ‘A, B, C, D’ Dim delimStr As String = ‘ ,’ Dim delimiter As Char() = delimStr.ToCharArray() Dim s As String For Each s In myString.Split(delimiter) Response.Write((s.ToString() + ‘<br>’)) Next C# string myString = ‘A, B, C, D’; string delimStr = ‘ ,’; char[] delimiter = delimStr.ToCharArray(); foreach (string s in myString.Split(delimiter)) { Response.Write (s.ToString ()+ ‘<br>’); }

How to set a <link> tag’s href attribute at runtime using a value specified in the web.config file

web.config <configuration> <appSettings> <add key=’CSS1′ value=’StyleSheet1.css’ /> </appSettings> </configuration> .aspx <link id=’link1′ runat=’server’/> VB.NET Dim lnk As New System.Web.UI.HtmlControls.HtmlGenericControl(‘lnk’) lnk = CType(Me.Page.FindControl(‘link1’), System.Web.UI.HtmlControls.HtmlGenericControl) lnk.Attributes.Add(‘rel’, ‘stylesheet’) lnk.Attributes.Add(‘href’, ConfigurationSettings.AppSettings(‘CSS1’).ToString()) lnk.Attributes.Add(‘type’, ‘text/css’) C# System.Web.UI.HtmlControls.HtmlGenericControl lnk =new System.Web.UI.HtmlControls.HtmlGenericControl (‘lnk’) ; lnk =(System.Web.UI.HtmlControls.HtmlGenericControl ) this.Page.FindControl( ‘link1’) ; lnk.Attributes.Add (‘rel’, ‘stylesheet’); lnk.Attributes.Add (‘href’, ConfigurationSettings.AppSettings[‘CSS1’].ToString()) ; lnk.Attributes.Add (‘type’,’text/css’);

How to dynamically load User Controls

Create a User Control <P> <asp:Button id=’Button1′ runat=’server’ Text=’Button’></asp:Button></P> <P> <asp:Label id=’Label1′ runat=’server’></asp:Label></P> On button Click VB.NET Label1.Text = ‘Hello’ C# Label1.Text = ‘Hello’ ; Create a Webform to use a UserControl <asp:Panel id=’Panel1′ runat=’server’></asp:Panel> VB.NET Dim myControl As Control = CType(Page.LoadControl(‘UC1.ascx’), Control) Panel1.Controls.Add(myControl) C# Control myControl =(Control)Page.LoadControl(‘UC1.ascx’); Panel1.Controls.Add(myControl);

How to show the ASP.NET code to the users

Use namespace System.IO System.Text VB.NET Protected Function GetCode(filename As String) As String Dim sr As New StreamReader(filename) Dim sb As New StringBuilder() sb.Append(‘<code><pre>’) sb.Append(sr.ReadToEnd()) sb.Append(‘</pre></code>’) sr.Close() Return sb.ToString() sb = Nothing sr = Nothing End Function ’GetCode Private Sub Button1_Click(sender As Object, e As System.EventArgs) Response.Write(GetCode((Server.MapPath(‘WebForm1.aspx’) + ‘.vb’))) End Sub ’Button1_Click C# protected string GetCode(string filename) { StreamReader sr =new StreamReader(filename ); StringBuilder sb =new StringBuilder(); sb.Append(‘<code><pre>’); sb.Append(sr.ReadToEnd()); sb.Append(‘</pre></code>’); sr.Close(); return sb.ToString(); sb = null; sr = null; } private void Button1_Click(object sender, System.EventArgs e) { Response.Write (GetCode(Server.MapPath (‘WebForm1.aspx’) + ‘.cs’)); }

How to select a specific Item in a ListBox in code

VB.NET ListBox1.Items.FindByValue(<Value>).Selected = true ’ListBox1.Items.FindByText(<Text>).Selected = true C# ListBox1.Items.FindByValue(<Value>).Selected = true; //ListBox1.Items.FindByText(<Text>).Selected = true;