ferguson_jerald
asked on
How to hide an asp:textfield and exclude it from the form layout, or pass a value without using the asp:textfield?
Hello Experts,
I have an asp.net application with a form that captures some information that is stored in a MS SQL database. I would like to know who creates each record. I currently have an asp:textbox that captures the current user with:
Do I need this text field at all?
If yes, how do I hide the field from the layout and still pass the value of creator_txt to the database?
If not, how do I pass the current user to @creator without using the text field?
I hope this makes sense. Please ask questions if it's not clear.
I am using Visual Studio 2012, SQL Server Management Studio 2012, asp.net and c#.
Thanks,
J
I have an asp.net application with a form that captures some information that is stored in a MS SQL database. I would like to know who creates each record. I currently have an asp:textbox that captures the current user with:
creator_txt.Text = System.Web.HttpContext.Current.User.Identity.Name;
Then I use that text field in a SqlCommand and insert it into a MS SQL Server table using:SqlCommand new_record_cmd = new SqlCommand("Insert Into tbl(record_nm, creator) Values @record_nm, @creator)))", lcms_cnxn);
new_record_cmd.Parameters.AddWithValue("@record_nm", record_nm_txt.Text);
new_record_cmd.Parameters.AddWithValue("@creator", creator_txt.Text);
lcms_cnxn.Open();
new_record_cmd.ExecuteNonQuery();
lcms_cnxn.Close();
It all works just fine, but I would like this field to be hidden - it doesn't need to be visible in the form. Do I need this text field at all?
If yes, how do I hide the field from the layout and still pass the value of creator_txt to the database?
If not, how do I pass the current user to @creator without using the text field?
I hope this makes sense. Please ask questions if it's not clear.
I am using Visual Studio 2012, SQL Server Management Studio 2012, asp.net and c#.
Thanks,
J
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi you can use Hiddenfield or Label to do this.
ASKER
Thanks. But what do I do to my code behind to get it to work properly? I currently have:
What do I replace the
creator_txt.Text = System.Web.HttpContext.Current.User.Identity.Name;
.What do I replace the
.Textin
creator_txt.Textwith? When I remove it I get
Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls..HiddenFie ld
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks - it worked as expected.