title: ASP.net UserControl Parameter Passing
body: <p>I am a newbie developer. I am creating a page + a user control. The aspx page contains a dropdownlist which is populated by a sql datasource that is on aspx page. The ascx page contains a gridview which is popluated by another sql datasource that is on ascx page.</p>
  
  <p>The dropdownlist on aspx has a list of countries and the gridview (on ascx) should display data depending on the selected country.</p>
  
  <p>My ascx page as follow.</p>
  
  <pre><code>    Partial Class UCtest
      Inherits System.Web.UI.UserControl
  
      Private priCountry As String
  
      Public Property PublicCountry() As String
  
      Get
          Return priCountry
      End Get
      Set(ByVal value As String)
          priCountry = value
      End Set
  
      End Property
  
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
      SqlDataSource1.SelectParameters.Add("Country", priCountry)
  
      End Sub
      End Class
  
      &lt;%@ Control Language="VB" AutoEventWireup="false" CodeFile="UCtest.ascx.vb" Inherits="UCtest" %&gt;
      &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
      DataSourceID="SqlDataSource1" 
      EmptyDataText="There are no data records to display."&gt;
      &lt;Columns&gt;
      &lt;asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
          SortExpression="CompanyName" /&gt;
      &lt;asp:BoundField DataField="Country" HeaderText="Country" 
          SortExpression="Country" /&gt;
      &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;" 
  
      SelectCommand="SELECT [CompanyName], [Country] FROM [Customers] WHERE ([Country] = ?)"&gt;
      &lt;SelectParameters&gt;
  
      &lt;/SelectParameters&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>My aspx page</p>
  
  <pre><code>    &lt;%@ Register src="UCtest.ascx" tagname="UCtest" tagprefix="uc1" %&gt;
      &lt;asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
      DataSourceID="SqlDataSource1" DataTextField="Country" DataValueField="Country"&gt;
      &lt;/asp:DropDownList&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;" 
      SelectCommand="SELECT DISTINCT [Country] FROM [Customers]"&gt;&lt;/asp:SqlDataSource&gt;
  
      &lt;uc1:UCtest ID="UCtest1" runat="server" /&gt;
  
      Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
  
      UCtest1.PublicCountry = DropDownList1.SelectedValue
  
      End Sub
  </code></pre>
  
  <p>It works fine if I just pass static values such as </p>
  
  <pre><code>    &lt;uc1:UCtest ID="UCtest1" runat="server" PublicCountry="Mexico"/&gt;
  </code></pre>
  
  <p>So I think I properly linked the User Control. But when I run the page, I only get blank page which mean ascx doesn't get data from aspx. what am I missing? </p>