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 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;

Open in new window

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);


Open in new window

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, and c#.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use asp:HiddenField:
<asp:HiddenField id="creator" runat="server" />

Open in new window

It will create a input type="hidden" element on the web page
Mandeep SinghDatabase AdministratorCommented:
Hi you can use Hiddenfield or Label to do this.
ferguson_jeraldAuthor Commented:
Thanks.  But what do I do to my code behind to get it to work properly?  I currently have:

creator_txt.Text = System.Web.HttpContext.Current.User.Identity.Name;

Open in new window

What do I replace the
with?  When I remove it I get
Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.HiddenField
I often use Labels and set them to Visible = False. Then you can still use the .Text property.

If you use the HiddenField, you reference the .Value property.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ferguson_jeraldAuthor Commented:
Thanks - it worked as expected.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.