I was wondering if I can add a user control to a page with a parameter, and then access this parameter in the code for initialization.
For example, on my aspx page, I would have something similar.
<%@ Register TagPrefix="uc1" TagName="myMap" Src="~/Map.ascx" %>
blah
blah
blah
<uc1:myMap ID="myMap1" runat="server" DefaultCountry="UnitedStates"/>
How to access the DefaultCountry parameter in my Map.ascx.cs file behind the file.
If I do not agree with this, then what is the correct implementation?
EDIT:
It revealed
on the .aspx page
<uc1:myPartnerMap ID="MyPartnerMap1" runat="server" defaultCountry="USA"/>
in .ascx.cs user control
private string defaultCountry;
public String DefaultCountry
{
get { return defaultCountry; }
set { defaultCountry = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CountrySelector.SelectedValue = defaultCountry;
}
}
source
share