You can create a property on the user control to expose the property on the hidden field like so:
public int AlbumID
{
get { return Convert.ToInt32(txtAlbumID.Value); }
set { txtAlbumID.Value = value.ToString(); }
}
You should then be able to wire the object data source to the user control:
<asp:ControlParameter Name="albumID" ControlID="myUserControl" PropertyName="AlbumID" Type="Int32"/>
Edit:
There are a few ways to go the other way around (i.e., data source in the user control). One approach is viable, but I find makes for some designer confusion, is to expose the parameter collection from the user control as a public property:
public ParameterCollection SelectParameters
{
get { return ObjectDataSource1.SelectParameters; }
}
Doing so allows you to fill the parameter collection from the page like so:
<my:UserControl runat="server" ID="myUserControl">
<SelectParameters>
<%-- ... --%>
</SelectParameters>
</my:UserControl>
If you use a designer, your control will always display an error, but it works. (Note, that I've used this approach with query string and session parameters. It would be interesting to see if it will survive control parameters.)
I think, though, that the easiest method is to swap out your ControlParameter
for a plain old Parameter
, and expose the default value through a property.
public int AlbumID
{
get { return Convert.ToInt32(ObjectDataSource1.Parameters[0].DefaultValue); }
set { ObjectDataSource1.Parameters[0].DefaultValue = value.ToString(); }
}
You can then data bind or assign directly to the AlbumID property of the control, and expect the value to be forwarded to the parameter.