Posts

Showing posts from February, 2012

.Net C# Date and Time functions and Displaying the Month using a case statment.

//Note: Literal1 refers to a Literal Control that needs to be created on your form.         protected void dateAndTime()         {             // Create a Time Object             DateTime myTime = DateTime.Now;             // Display the Year             Literal1.Text = "The Year is: " + myTime.Year;             // Display the Time             Literal1.Text += "<br />  The Time is: ";             Literal1.Text += myTime.Hour + ":" + myTime.Minute + ":" + myTime.Second;             // Display the Month             Literal1.Text += "<br /> The Month is: ";             String thisMonth;             thisMonth = getMonth(myTime.Month); // Call the Month Function             Literal1.Text += myTime.Month + " (" + thisMonth + ")";                    }         String  getMonth(int monthIn)         {             int caseSwitch = monthIn;             string monthOut;             switch (cas

.Net Web Config File Enable Application Tracing for Remote. Web

1).  In the <system.web> part of the Web.Config 2) Paste in the following:  <trace pageOutput="false" requestLimit="10" enabled="true" localOnly="false" traceMode="SortByTime" mostRecent="true"/>

.NET C# HtmlEncode and HtmlEncode - Turn a String in to Valid HTML - Turn valid HTML In to a normal String. Web

       // Turn a String in to Valid HTML         var myVaildHtml = Server.HtmlEncode("blah & blah");  //  Will turn the & into &amp;         Response.Write(myVaildHtml);         //Turn valid HTML In to a normal String         var myNormalString = Server.HtmlDecode(myVaildHtml);  // Will reverse the &amp; back to &         Response.Write(myNormalString);

.NET C# Display a Text File - TransmitFile - In the Browser. Web

    protected void transmitTextFile()     {         Response.TransmitFile("C:\\Copies\\Temp.txt");     }

.NET C#, Permanent 301 Redirect, Temporary 302 Redirect. Web

    protected void permanentRedirect ()     {         // 302 A PERMANENT REDIRECT         Response.RedirectPermanent(" http://www.markdownie.me.uk/ ");     }     protected void temporaryRedirect()     {         // 301 A TEMPORARY REDIRECT         Response.Redirect(" http://www.markdownie.me.uk/ ");     }    

.Net C# Get last URL, Get Current URL. Web

    protected void displayUrlInfo ()     {         Response.Write("<br /> Request.Url - Current URL: " + Request.Url);         Response.Write("<br /> Request.UrlReferer - URL you Came From: " + Request.UrlReferrer);              }

.Net c# Get or Display Browser Information. Web

    protected void displayBrowserInfo ()     {         Response.Write("<br /> Browser: " + Request.Browser.Browser);         Response.Write("<br /> Version: " + Request.Browser.Version);         Response.Write("<br /> Cookies Enabled:" + Request.Browser.Cookies);         Response.Write("<br /> Javascript Version: " + Request.Browser.JScriptVersion);        }

.Net Dynamicaly Create and Remove a Control / Object, such as a button. Web

    private void CreateControls()     {         // Create a New Button         Button myButton = new Button();         // Give the Button Some Properties         myButton.Text = "A Dynamicaly Created Button";         // Add Button to PlaceHolder         // ** NOTE: The Planel must Exist in your design view         Panel1.Controls.Add(myButton);               }     private void RemoveButton()     {         // Search for the button in the Page Controls Collection         Button foundButton = (Button)Page.FindControl("myButton");         // Remove the Button         if (foundButton != null)         {             foundButton.Parent.Controls.Remove(foundButton);         }     }

.Net C# Dynamicaly Creating Page.Header Title, Keywords and Description. Web

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Accessibility; public partial class _Default : System.Web.UI. Page { { Page.Header.Title = protected void Page_Load( object sender, EventArgs e) "Dynamicaly Titled Page" ; // VERSION 1: You can use Page.MetaDescription and Page.MetaKeywords Page.MetaDescription = Page.MetaKeywords = "Dynamicaly Created Meta Data Description" ; "Dynamic, Created, Keywords" ; // VERSION 2: or use Page.Header.Keywords and Page.Header.Description Page.Header.Keywords = Page.Header.Description = } } "More, Dynamic, Keywords" ; "More, Dynamic, Created, Keywords" ;

.Net C# write out all the controls that appear on your page. Web.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Accessibility; public partial class _Default : System.Web.UI. Page { { protected void Page_Load( object sender, EventArgs e) // Start Examning all the Controls DisplayControl(Page.Controls, 0); Response.Write(     }   { { "<hr /" ); private void DisplayControl( ControlCollection controls, int depth) foreach ( Control control in controls) // Use the depth paramater to indent the control tree. Response.Write( new String ( '-' , depth * 4) + "> " ); // Display this control Response.Write(control.GetType().ToString() + control.ID + { DisplayControl(control.Controls, depth + 1); } } }   } " - <b>" + "</b><br />" ); if (control.Controls != null )

.NET C# Page Flow. Web

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Accessibility; public partial class _Default : System.Web.UI. Page { { { lblInfi.Text = ( } } { lblInfi.Text += } { lblInfi.Text += } { protected void Page_Load( object sender, EventArgs e) if (!IsPostBack) "<b>This is the 1st time this page has been loaded.</b><br />" ); private void Page_Init( object sender, EventArgs e) "Page.Init Event Handled.<br />" ; private void Page_PreRender( object sender, EventArgs e) "Page.PreRender Event Handled.<br />" ; private void Page_Unload( object sender, EventArgs e) // This Text will never appear because the HTML is alread // Rendered lblInfi.Text += } { } } "Page.Unload Event Handled.<br />" ; protected void cmdOk_Click( object sender, EventArgs e)