Suppose you want to bind a grid for asp.net in a user control to an ObjectDatasource.
It is a problem if the subroutine for the SelectMethod of the ObjectDatasource has a parameter whose value depends on user context or on a value in another control on the user control.
You cannot get this parameter value in the code-behind of the user control. For example, the subroutine for the SelectMethod could be in the code-behind of the user control.
BUT it will not work. Because the ObjectDatasource activates this subroutine before there is any user context or any viewstate available in the user control.
So you cannot get the parameter value this way.
I solved the problem by:
1. Defining a label control (lblSCS_ID in this case ) in the user control that will be the source of the parameter value
<asp:ObjectDataSource ID="ObjDataSourceGetPGC2forSCS_ID" runat="server" TypeName="BalancedFlow.Library.Manager.SCSManager"
SelectMethod="GetPGC2forSCS" EnablePaging="false">
<SelectParameters>
<asp:ControlParameter Name="SCS_ID" ControlID="lblSCS_ID" PropertyName="Text" />
</SelectParameters>
2. In the OnPreRender of the code-behind of the user control I set the value of the parameter.
lblSCS_ID.Text = UserContext.Session.ScsId.Value.ToString();
Now when the ObjectDatasource activates the SelectMethod it will get the parameter value from lblSCS_ID.Text (The parametervalue will already be there).