Having not found an acceptable answer after searching the internet for 3 days; this is what works:
Using an example of inserting a user name and returning an Id...
Create a stored procedure similar to this:
create procedure Users_Insert
@UserName varchar(25)
,@UserId int = null output
as
insert into Users (UserName) values (@UserName)
select @UserId = scope_identity();
return @UserId;
Now in your aspx page configure your SqlDataSource as such:
<asp:SqlDataSource ID="dsUsers" runat="server"
ConnectionString="<%$ ConnectionStrings:dbConnection %>"
InsertCommand="Users_Insert" InsertCommandType="StoredProcedure" OnInserted="dsUsers_Inserted">
<InsertParameters>
<asp:ControlParameter ControlID="txtUserName" Name="UserName" Type="String" PropertyName="Text" />
<asp:Parameter Name="UserId" Type="Int32" Direction="ReturnValue" />
</InsertParameters>
</asp:SqlDataSource>
Note the OnInserted event is wired up.
Now, in your code behind, perhaps in a Save button click event, call the insert method:
dsUsers.Insert();
And finally, in the dsUsers_Inserted method that we previously wired up, get the identity:
protected void dsUsers_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
int userId = Convert.ToInt32(e.Command.Parameters["@UserId"].Value);
}
Hope this helps at least one person.
Happy coding!