How do I insert the UserName of the Logged in user into the
DB field UserID. I created a web form page, and added a form
view control set the page default to Insert Mode. The Page is used to insert
data. I have a hidden field called UserID that I would like to capture the Logged in
user. I have been trying to figure out what I am doing worng, but no luck, Please suggest
the best way to do this. I have listed what I have done thus far?
System.aspx---------------------------------------------------------------------------------------------------------------
1) <asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="SystemID"
DataSourceID="SystemSqlDataSource1" DefaultMode="Insert" Width="583px">
2) <asp:TextBox ID="UserIDTextBox" runat="server"
Text='<%# Bind("UserID") %>' Visible="False"></asp:TextBox><br />
3) <asp:SqlDataSource ID="SystemSqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RCMISConnectionString %>"
DeleteCommand="DELETE FROM [tblSystem] WHERE [SystemID] = @SystemID" InsertCommand="INSERT INTO [tblSystem] ([SystemID], [SystemDesc], [Inactive], [TimeStampEntry], [TimeStampUpdate], [UserID]) VALUES (@SystemID, @SystemDesc, @Inactive, GETDATE(), @TimeStampUpdate, @UserID)"
4) <InsertParameters>
<asp:Parameter Name="SystemID" Type="String" />
<asp:Parameter Name="SystemDesc" Type="String" />
<asp:Parameter Name="Inactive" Type="Boolean" />
<asp:Parameter Name="TimeStampEntry" Type="DateTime" />
<asp:Parameter Name="TimeStampUpdate" Type="DateTime" />
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="@UserId" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
System.aspx.
vb---------------------------------------------------------------------------------------------------------
5) Partial Class MemberPages_RCM_frmSystem
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'UserIDTextBox.Text = Membership.GetUser().ProviderUserKey.ToString()
End Sub
Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArg s) Handles FormView1.ItemInserted
'Set the UserID Value to the currently logged on user's ID
e.Values("UserID") = Membership.GetUser().ProviderUserKey
End Sub
End Class
Thank you in advance,