Archive for Luglio 14th, 2008

Temp Files & Folders

CodeKeep C# Feed Luglio 14th, 2008

Description: Even need the location of the system temp folder or need to create a temp file on the fly?

Link: http://www.codekeep.net/snippets/02aee708-22b1-466d-880c-2d651619c980.aspx

// the system's temp files/folder
string tempPath = System.IO.Path.GetTempPath();
string tempFile = System.IO.Path.GetTempFileName();

      

StreamReader

CodeKeep C# Feed Luglio 14th, 2008

Description: StreamReader

Link: http://www.codekeep.net/snippets/b3f0f963-9ae9-4e33-a8da-b32187650ace.aspx

using (StreamReader reader = new StreamReader(new FileStream(m_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))

How to Create an Ajax Autocomplete Text Field: Part 7

WebReference News Luglio 14th, 2008

In this series we've built a fully functional Autocomplete control within Eclipse. For the remaining installments, we'll be updating the Autocomplete control's layout to CSS, decoupling it from the Autocomplete.jsp page, tweaking the appearance of the list, and implementing additional functionality. By Rob Gravelle. 0522

TableLayoutPanel

CodeKeep C# Feed Luglio 14th, 2008

Description: TableLayoutPanel Sample

Link: http://www.codekeep.net/snippets/67e019ef-4904-4c9f-a302-6cf6ac15afa9.aspx

private void IntializeTableLayoutPnl()
        {
            TableLayoutPanel tableLayoutPanel2 = new TableLayoutPanel();
            tableLayoutPanel2.Dock = DockStyle.Fill;
            tableLayoutPanel2.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
            this.Controls.Add(tableLayoutPanel2);
            for (int row = 0; row < 5; row++)
            {
                Label text = new Label();
                text.Text = "text";
                tableLayoutPanel2.Controls.Add(text);
            }
        }

RadioButtonList Custom Validator

CodeKeep C# Feed Luglio 14th, 2008

Description: RadioButtonListValidator

Link: http://www.codekeep.net/snippets/90372be6-f442-413d-a498-b289d5ba91df.aspx

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Esc.Common
{
	/// <summary>
	/// Custom Validator for RadioButtonList Control.
	/// </summary>
	public class RadioButtonListValidator : BaseValidator
	{
		private RadioButtonList controlToValidate;

		protected RadioButtonList RadioButtonListToValidate
		{
			get
			{
				if (controlToValidate == null)
					controlToValidate = FindControl(ControlToValidate) as RadioButtonList;

				return controlToValidate;
			}
		}

		protected override bool ControlPropertiesValid()
		{
			// make sure ControlToValidate is set.
			if (ControlToValidate.Length == 0) throw new HttpException(string.Format(Resources.Messages.ControlToValidatePropertyCannotBeBlank, ID));

			// ensure that the control being validated is a RadioButtonListToValidate.
			if (RadioButtonListToValidate == null) throw new HttpException(string.Format(Resources.Messages.RadioButtonListValidatorCanOnlyValidateRadioButtonList));

			// it's good.
			return true;
		}

		protected override bool EvaluateIsValid()
		{
			// only one test currently performed.
			return EvaluateIsChecked();
		}

		protected bool EvaluateIsChecked()
		{
			RadioButtonList radioButtonList = RadioButtonListToValidate;

			foreach (ListItem li in radioButtonList.Items)
			{
				// if any item is selected then the method returns true.
				if (li.Selected) return true;
			}

			// no item was selected.
			return false;
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);

			// Register the client-side function using WebResource.axd (if needed)
			// see: http://aspnet.4guysfromrolla.com/articles/080906-1.aspx
			if (RenderUplevel && Page != null && !Page.ClientScript.IsClientScriptIncludeRegistered(GetType(), "Validators"))
			{
				Page.ClientScript.RegisterClientScriptInclude(
					GetType(),
					"Validators",
					Page.ClientScript.GetWebResourceUrl(GetType(), "Esc.Common.Resources.Validators.js"));
			}
		}

		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			base.AddAttributesToRender(writer);

			// Add the client-side code (if needed).
			if (RenderUplevel)
			{
				Page.ClientScript.RegisterExpandoAttribute(
					ClientID, 
					"evaluationfunction",
					"RadioButtonListValidatorEvaluateIsValid",
					false);
			}
		}
	}
}