Welcome to ASP.NET Guild

Be sure to come back often and tell others. If you have any tips, tricks, examples, please email them to me at chris.williams@techguilds.com and I will post them. Check out our ASP.NET QuickStart and C# QuckStart Libraries. Below is my latest articles.

Friday, May 19, 2006

Creating Custom Web Controls (Server Controls)

The following are links to examples on how to create a variety of custom web controls

If you have any more custom web control links to share please email them to me at
chrisw_88@hotmail.com

Wednesday, May 10, 2006

How To Change Master Pages Dynamically at runtime

Changing MasterPages dynamically is a simple task, but there is a catch. MasterPage can be changed in PreInit page or earlier. At this stage control tree is not constructed yet. The question is: "How can we use postback event to change MasterPage?" Usual solution for this problem is to save selected MasterPage file name into session, reload page and in PreInit set MasterPage according to persisted value. This works but requires additional roundtrip. Another solution is to intercept postback events in PreInit and process it, so here it is:


ASPX:
@ Page MasterPageFile="~/MasterPage.master" Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<asp:DropDownList ID="MasterSwitch" runat="server" AutoPostBack="true">
<asp:ListItem Text="Simple Layout" Value="MasterPage.master">asp:ListItem>
<asp:ListItem Text="Complex Style" Value="MasterPageComplex.master">asp:ListItem>
<asp<:DropDownList>
<div<>>
<asp<>:Content>


Codebeside:
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
switchMaster();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session[
"MasterSwitch"] = this.MasterSwitch.UniqueID;
}
}
private void switchMaster()
{
if (IsPostBack)
{
// Get control that fire postback event
string eventTarget = Request.Form["__EVENTTARGET"];
if (String.IsNullOrEmpty(eventTarget))
return;
// At this stage we don't have control tree yet,
// so we'll use previosly saved control ID
string switchControlName = (string)Session["MasterSwitch"];
if (String.IsNullOrEmpty(switchControlName))
return;
if (String.Compare(eventTarget, switchControlName, true) != 0)
return;
setMaster(Request.Form[eventTarget]);
}
}
private void setMaster(string masterName)
{
if (String.IsNullOrEmpty(masterName))
return;
// In real implementation some logic to convert
// selected value into real MasterPage File Name should be here
if (String.Compare(this.MasterPageFile, masterName, true) != 0)
this.MasterPageFile = masterName;
}
}




If you have any additional tips, tricks etc that you would like me to post to my blog, please email them to me at chrisw_88@hotmail.com




Wednesday, March 29, 2006

Multilingual characters in web.config

This is a good article on placing Multilingual characters in web.config

http://blogs.imason.com/chris.chapman/archive/2005/10/05/1833.aspx



If you have any additional tips, tricks etc that you would like me to post to my blog, please email them to me at chrisw_88@hotmail.com

Monday, March 20, 2006

Common Solution Links

This article will contain a list of other sites to find solutions to common problems.






If you have any suggestions for links to place here please email them to me at chrisw_88@hotmail.com

Wednesday, March 08, 2006

CTW ASP.NET Grid articles

Below is a good article on the gridview control:

http://www.gridviewgirl.com/GridViewGirl/articles.aspx



If you have any additional tips, tricks etc that you would like me to post to my blog, please email them to me at chrisw_88@hotmail.com

Monday, February 06, 2006

GridView Tips and Tricks

This article will contain a list of tips and tricks related to the using the GridView.










Formatting data using DataFormatString

EXAMPLE:


I was having an issue with it not applying my format. If it doesn’t work its one of the 3 key reasons below.For me I did not have HtmlEncode set to false.

The key properties are as follows:

o HtmlEncode = "False" ensures that the formatting is applied when displaying the date field. Without it, the formatting doesn't apply for some unknown reason.

o ApplyFormatInEditMode = "True" ensures that the DataFormatString is also applied when you change to the Edit mode. Without it, the formatting is ignored in Edit mode.

Introduction

Welcome to the ASP.NET 2.0 Tips and Tricks page.

This blog is designed to contain various Tips and Tricks to help you with your ASP.NET 2.0
development. Since there are a lot of changes from ASP.NET 1.1 to 2.0 hopefully this will
help you with some of the pot-holes found during transition from 1.1 to 2.0 as well.

If you know any Tips or Tricks I can add to this blog please email them to me at chrisw_88@hotmail.com

Are you a .NET Developer or Contractor interested in working with Sitecore or Dynamics CRM?

Apply for our Mentorship Program. If accepted, we will mentor you on Sitecore and provide you with project to help you build your skills and make some money at the same time. If you are interested send your resume with details on why you want to work with Sitecore or Dynamics CRM to: Chris Williams - chris.williams@techguilds.com or Dennis Augustine - dennis.augustine@techguilds.com We look forward to working with you to achieve your goals.