I am using dynamic programmatic addition of a SqlDataSource in the page_init handler using Me.Controls.Add(sds) where sds is the SqlDataSource.
Then I set the trgrid.DataSourceID = sds.ID and trgrid.MasterTableView.DataSourceID = sds.ID and do a trgrid.Rebind().
And everything works fine on initial page access, postbacks, etc, as long as I do NOT put the code in a If Not Page.IsPostBack block.
If I do put it in a If Not Page.IsPostBack block then the initial page access works fine, but any postback bombs with the following error:
The DataSourceID of 'trgrid' must be the ID of a control of type IDataSource. A control with ID 'sds' could not be found.
So how to fix this error? Should the If Not Page.IsPostBack block of code for programmatic addition of the SqlDataSource be put in a different event handler other than the Init event handler?
Then I set the trgrid.DataSourceID = sds.ID and trgrid.MasterTableView.DataSourceID = sds.ID and do a trgrid.Rebind().
And everything works fine on initial page access, postbacks, etc, as long as I do NOT put the code in a If Not Page.IsPostBack block.
If I do put it in a If Not Page.IsPostBack block then the initial page access works fine, but any postback bombs with the following error:
The DataSourceID of 'trgrid' must be the ID of a control of type IDataSource. A control with ID 'sds' could not be found.
So how to fix this error? Should the If Not Page.IsPostBack block of code for programmatic addition of the SqlDataSource be put in a different event handler other than the Init event handler?