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) {
		base.OnLoad(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; }
    }
Advertisements

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

  1. Pingback: Passing Parameters To WebControls « Derek Reynolds – Brain Dump-O-Matic

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s