Passing Parameters From Page (aspx) to WebControl (ascx) Where control exists in another project

When a WebControl exists in the same project as the related page you can easily pass params in the Control directive within the page. In the example below we want to pass the StateCode of KY:

<gcl:GreenPricingControl id="GreenPricingControl" runat="server" StateCode="KY"></gcl:GreenPricingControl>

If the WebControl exists outside of the project you must append the following to the page where the WebControl directive sits:

	protected override void OnLoad(EventArgs e) {
        GlobalUserControl2.SetProperty("StateCode", "KY");

And in your WebControl create a property for it to be available:

public string StateCode
        get {
            if (ViewState["StateCode"] == null) { ViewState["StateCode"] = ""; }
            return (string)ViewState["StateCode"];
        set { ViewState["StateCode"] = value; }

Excluding A Web Site From Building When Debugging (F5)

From Jared:

Inline code is great.

You can update any site by just pushing out one file with your code in it, and all references to that file are set. However, the downside is that the capability that allows you to do that (on-demand compiling) is the same thing that holds you back when debugging if you compile the site before debugging (which is the default).

Output Window

Even worse… debugging makes you compile every site, most of which aren’t even relevant to your test.

Luckily there’s an easy way around this.

1. Go to the property pages of your site (Solution Explorer > Right-click solution > Property Pages…).
2. On the “Build” tab, set the “Before running startup page” action to “No Build”

No Build

Do this for every web site in your solution except the one your localhost is set to. This should cut wait time down dramatically.

Formatting Code in WordPress

Wrap your code in these tags:

[sourcecode language=’css’]

your code here


Any of the following can be used for the language parameter (using one is required):

  • bash
  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • shell
  • sql
  • vb
  • xml

Code in between the [sourcecode] tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.


string test;
class cls = new class;

string[] stringArray;

Good pattern for DIV Tables

Good pattern for div tables

/* divTable */
.divTable { position: relative; }
.divTable .row { position: relative; }
.divTable .row .c1 { position: absolute; top: 0px; }
.divTable .row .c2 { position: absolute; top: 0px; }
.divTable .row .c3 { position: absolute; top: 0px; }

/* change the divTable dimensions for different situations (always set .row height) */
.LShape .divTable { width: 682px; }
.LShape .divTable .row .c1 { left: 0px; width: 227px; }
.LShape .divTable .row .c2 { left: 227px; width: 227px; }
.LShape .divTable .row .c3 { left: 454px; width: 228px; }
.LShape .divTable .indented { padding: 0px 13px; }

Note:  c2 starts where c1 left off and c3 starts where c2 ends.

RolloverImageButton WebControl (emulates HTML IMG onMouseOver/onMouseOut)

Unlike HTML tags which support onMouseOver and onMouseOut, ASP.NET ImageButton’s do not.

I created a WebControl that overrides some of the default behaviors of the regular ImageButton mimicking the inline JavaScript functionality for onMouseOver and onMouseOut.

WebControl Code:  [RolloverImageButton.cs]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Utilities.Common.WebControls.Buttons
/// <summary>
/// RolloverImageButton emulates the <img> equivelent of onMouseOver and onMouseOut
/// allowing image swapping.
/// </summary>
/// <usage>
/// Static Image:
///      ImageUrl="/global/utilities/lib/images/content/account/bills/pay/btn_PayNowAtBillMatrix.gif"
/// Rollover Image:
///      ImageOverURL="/global/utilities/lib/images/content/account/bills/pay/btn_PayNowAtBillMatrixRO.gif"
/// </usage>

[ToolboxData("<{0}:RolloverImageButton runat=server></{0}:RolloverImageButton>")]
public class RolloverImageButton : ImageButton

#region public virtual string ImageOverUrl
public virtual string ImageOverUrl
if (null == ViewState["ImageOverUrl"])
return string.Empty;
return Convert.ToString(ViewState["ImageOverUrl"]);

set { ViewState["ImageOverUrl"] = value; }


// Overridden Methods
#region protected override void AddAttributesToRender(HtmlTextWriter writer)
protected override void AddAttributesToRender(HtmlTextWriter writer)
writer.AddAttribute("onMouseOver", "this.src='" + base.ResolveClientUrl(ImageOverUrl) + "'");
writer.AddAttribute("onMouseOut", "this.src='" + base.ResolveClientUrl(ImageUrl) + "'");




<%@ Register TagPrefix=”XXXbuttons” Namespace=”Utilities.Common.WebControls.Buttons” Assembly=”Utilities.Common” %>


<XXXbuttons:RolloverImageButton ID=”BtnAccept” runat=”server” AlternateText=”Pay bill now at BillMatrix” ImageUrl=”/global/utilities/lib/images/content/account/bills/pay/btn_PayNowAtBillMatrix.gif” ImageOverURL=”/global/utilities/lib/images/content/account/bills/pay/btn_PayNowAtBillMatrixRO.gif” OnClick=”BtnAccept_Click” /> 


Pay Now At Bill Matrix Rollover

Pay Now At Bill Matrix