I have a page with a formview on it. The formview is only used for inserts. I have 2 hidden textboxes which I use to set a username and datetime before the record insert. I cannot get these to work without an error. I just need to get these values into the record being written so if this is the wrong approach please advise. The error I get is:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
ion: Object reference not set to an instance of an object.
Line 69: t = c
Line 70: ' This line is for testing
Line 71: t.Text = "This is a test"
Line 72: t.Text = ugw.Membership.GetCurrentU
Line 73: c = frmEditInsert.FindControl(
Source File: c:\websites\MyWebsite\\Myf
b Line: 71
I added the test line to verify that the error was not from the function ugw.Membership.GetCurrentU
ge) which returns a string.
If the solution is to set the Insert parameters values that would work for me also.
Please advise which is best, to set bound textbox values or to set insert parameters, and which event to set them in.
Thanks in advance.
Protected Sub frmEditInsert_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmEditInsert.DataBound
Dim c As System.Web.UI.Control
Dim t As TextBox
c = frmEditInsert.FindControl("fldModifiedByTextBox")
t = c
' This line is for testing
t.Text = "This is a test"
t.Text = ugw.Membership.GetCurrentUserName(Page)
c = frmEditInsert.FindControl("fldDateModifiedTextBox")
t = c
t.Text = DateTime.Now.ToLocalTime