Using a Session field as default field value

Hi all,

I am brand new to ASP.NET, this is my first post here.

I have build a form, with a Formview control, set to Insert item. That page will be used to add record to a database.

I have a field called "Listing_Owner" which will store the Authentified user name.

I know how to get the User name, but I just don't know how to set the Username as default value for that owner field, which will be hidden.

I tried to write code in the Page_Load event, but it does not seems to find my field.

Any idea?

I hope it is clear, this is all new terms for me.

Thanks alot.

 


New to ASP... looking for answers!
0
webgig
5/4/2007 3:26:02 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
679 Views

Similar Articles

[PageSpeed] 30

Hi,

Ok some terms are a bit messed up but that's fine,
Their is one other thing ...

What exactly is that field you are talking about? Can you show us some source code of what you are doing? (press the button top-right of this editor to insert it)

What you are trying to do isn't that hard so with a bit more info your problem is solved Wink

Greets
Wim


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
deblendewim
5/4/2007 5:50:07 PM

Hi Wim,

Thanks for answering.

I fixed my issue, but I'll explain it for Knowledge purposes.

If you think it exist a better/easier way to realize what I was looking for, feel free to post it, I would really enjoy having good design tips on that new stuff for me.

 

I have a SQL db that store classified adds. (This is a test project... to learn). The structure of the table is pretty simple, 4 columns, that look like this :

Add_UNID : UniqueIdentifier
Add_Owner : varchar(50)
Add_Title : varchar(50)
Add_Description : varchar(max)

 I created a form called : AddNewItem.aspx. On that form, I use a Formview control, defaulted to Insert mode. On that form, I just want to show the Title and the Description field, but I need to populate the Add_Owner field, with the Username of the logged in user.

I founded how :

On the page_load event, I use that code to set a Session field called "Username" :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.IsAuthenticated Then
            Dim myUser As MembershipUser = Membership.GetUser
            Session("Username") = myUser.UserName.ToString()
        End If
End Sub

In the DATABOUND event of my Formview control, I use that code to fill the hidden Add_Owner field with the Username session field :

 Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
        If User.Identity.IsAuthenticated Then
            Dim myUser As MembershipUser = Membership.GetUser
            Dim fieldAddOwner As TextBox
            fieldAddOwner = Me.FormView1.FindControl("AddOwnerTextBox")
            fieldAddOwner.Text = myUser.UserName.ToString()
        End If
 End Sub

 And it is working well. It is getting populated, and I can now, use datagrid to show only user's record.

I hope it is understandable!! Programming is like wine, it gets better with time!! Big Smile

Thanks 

Webgig.

 


New to ASP... looking for answers!
0
webgig
5/4/2007 7:06:51 PM

The Username does not appear to be unique, where as the User UserId is a unique identifier.  I have not found one example which uses the unique identifier, all examples I've seen use the Username, like the example above.

 

Where are the examples that use the unique identifier to record user activity on data records that they change?

 

0
lou
5/10/2007 1:08:02 AM
Reply:

Similar Artilces:

Submitting Web forms fields to sql database by clicking on SUBMIT FORM and sending the form fields to email box
I have a created or designed a form to be stored in a SQL database table and at the same time when a user clicks on SUBMIT button the form fields will automatically goto the visitor email address immediately. Also i have created a database with tables for each of this forms Pls help i have over 10 forms designed but the problem of submitting them to the table database and the user email address is the challenge now.... You ned to familiarise yourself with the basics of database access in ASP.NET.  There are free tutuorials here: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/da...

How do I populate a form field based on the value entered in a different field
------_=_NextPart_001_01C6DF64.FB6BF38A Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi folks, I'm trying to create an HTML form that will refresh itself based on user input. In the POD for CGI it says that you can set the value of a named parameter by using something like: $query->param(-name=3D>'foo', -value=3D>'the value'); But it doesn't say (or at least I didn't see) anything about how to redisplay the form with the new value in the textbox (or a different textbox for that matter...

RE: How do I populate a form field based on the value entered in adifferent field
=20 -----Original Message----- From: Shawn Hinchy [mailto:shawn@hinchy.net]=20 Would you mind sharing the answer? I would assume it would have to be some sort of Javascript, am I wrong? Thanks, Shawn -------------------- Shawn Michael Hinchy shawn@hinchy.net Nope, no Javascript. I could have used JS, but I was looking for a server side solution, due to having to replace values in a textfield with values gotten from a database in my "real" project. I'm embarrassed to admit that it all boiled down to having a statement out of order. Here's the fina...

RE: How do I populate a form field based on the value entered in a different field
Would you mind sharing the answer? I would assume it would have to be some sort of Javascript, am I wrong? Thanks, Shawn -------------------- Shawn Michael Hinchy shawn@hinchy.net ...

Updating non-nullable field in SQL with default value through dynamic field
Hi, I'm running Server 2008 and the 3.5 sp 1 Dynamic Data. I've got a Dynamic Data application using Entity Framework for its model, and I have a non-nullable datetime field that I don't want to scaffold; I want the database's default value to go in every time. In my partial class in the entity project, I've decorated the field with [Scaffold(false)], and I've also set the field setter to be private. The field does not render out to the page (good), but it still expects a value and breaks when I try to submit the rest of my fields exposed in a DetailsView control. I...

Open web page in IE and populate fields on the form from my web form
To the dot net Knights.  Many humble thanks in advance from a dot net surf. We have an vb application that opens multiple instances of IE object, each to different web pages.  It then takes information from the current record in the app, populates fields on each of the web pages, and them submits the forms.  We are then able to look at the resulting web pages and quickly get the info we're looking for.This prevents us from having to manually navigate to each web site, enter the same information and then wait for the page to open.  If there is ...

CGI: How do I populate a form field based on the value entered in a different field
------_=_NextPart_001_01C6DF3D.236D5557 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi folks, =20 I'm trying to create an HTML form that will refresh itself based on user input. In the POD for CGI it says that you can set the value of a named parameter by using something like: =20 $query->param(-name=3D>'foo', -value=3D>'the value'); =20 But it doesn't say (or at least I didn't see) anything about how to redisplay the form with the new value in the textbox (or a different textbox for th...

Getting values from form fields and use them in a query...
Hello all, I'm a newbie in ASP .NET, Visual Studio .NET, C# and VB .NET so please bear with me if you find this question so "beginner" or stupid. I badly need to know how to get the value from a data form field and use it as an argument in an SQL query. I was used to manipulating form values in HTML that I somehow find it hard to shift to VB or C#. I don't know how to do this in a code-behind in VS using C# with Access as my database. If you could just direct me to a tutorial or link that will help/teach me in using VS forms inside ASP code-behinds or stuff like that so I amy ...

web form fields values export to excel
hii all,           i've a web page where some textboxes , buttons and dropdowns are there, i need to export whole form values to excel but without buttons, dropdown etc. means the selected value of dropdown should be there on excel but dropdown list should not be there.... can any1 help me??? Regards Anant Vijay Have a simple export to excel button that handles the click event to read all the textbox values and the dropdownlist values. Once, this is read, add it to an excel sheet with the following code. Protected Sub Butt...

Changing Value of a databound field in a .net form
I have a bound form field that contains a date.  I want to use a calendar control to set the value.  I created the calendar control and have a link to have it display.  When the user selects the date I have a server side function that is called, but I cannot reference the field that displays the date in the browser.  I think this is because the field is being generated in a template.  How do I reference the value of the display field ? Thank you in advance. Hey, Did you use the container control's FindControl method to try to get the reference to the control?&nbs...

Force unique input to field from web form into Oracle primary key field...
Help??? This must be a common thing to do but have not seen an example to reference. Must create a web input form dialogue box ( dbi/oracle/CGI module ) which allows user to input a string. String will be placed in table if it is unique. String must be unique since it is to be placed into a primary key field. How would one force or promt the user to enter a unique string by either: 1.) appending some characters onto the string before being inserted into database ( in case there is an identicle string in the table already - meaning the database requires a sea...

Copy 2 form field to one form field
I’m trying to copy data from the field Sikkerheds grupper (this field is a single value field name is sikgrp) and the field Indbliks grupper (this field is multi value field name is sjgrp) to the field group. When I’m using the following ecma function: function list() { v=new java.util.Vector(); v.add(flowdata.get('sikgrp'));v.add(flowdata.getObject('sjgrp')); return v; }; list(); I’m getting the error showing in the group field [[sjgrp: null], [sjgrp: null]] If I’m using the following function: function list() { v...

Compare a field to what a value would be if it were in that field
We have been caught more than once with an error that's easy to fall into, described below. What I would like is something like is a way to treat a value as it would be if it were assigned to an existing database column, e.g. WHERE field = CAST(value AS TYPEOF(field)) or maybe some field matching operator that implicitly casts the value to the fields type before the comparison, e.g. WHERE field MATCHES value The problem we hit can be happen in SQL or in the invoking application, but it goes something like: <pseudocode GripeAboutSyntax="OFF">...

Accessibility and form fields using Visual Studio .NET
I am using VS .NET 2003 and am in charge of making sure our applications are accessible. I have found no easy way to associate form fields with their associative labels. Section 508 outlines using the 'label for/id" combination for accessibility but VS.NET 2003 gives no easy way to do this outside of going into the code. I don't understand why this feature isn't included in 2003. Is there an easier way to code this or what are future plans in the next release? I am trying to figure out the easiest way for our developer team to code for accessibility. Any help would be GREATLY...

Web resources about - Using a Session field as default field value - asp.net.web-forms

Joint session of the United States Congress - Wikipedia, the free encyclopedia
Joint sessions of the United States Congress are the gatherings together of both houses of the United States Congress (the House of Representatives ...

Houston schools in session in spite of threatening email - abc13.com
Houston ISD is sending parents across the school district automated phone calls, notifying them of a threat it received.

Q&A Session with ASUS at CES 2016: 10 Years of the Republic of Gamers
As part of our coverage of CES 2016 a few short weeks away, we have teamed up with ASUS for a round-table into their Republic of Gamers (ROG) ...

"LOYALTY HAS BEEN REPAID WITH BETRAYAL" Jeff Sessions Slams Paul Ryan for Mocking American Workers
By Julia Hahn While members of House Freedom Caucus are giving Rep. Paul Ryan (R-WI) a public pass on the omnibus, populist thought leader Sen. ...

Sen. Jeff Sessions: Omnibus a ‘Betrayal’, Increases Foreign Workers, Fully Funds Obama Immigration Agenda ...
Sen. Jeff Sessions (R-AL) slammed the immigration implications of the year-end spending bill Wednesday.

Mass shootings a major topic of Obama’s question and answer session - Videos - CBS News
President Obama wrapped up business at the White House with a wide ranging question and answer session in the briefing room yesterday before ...

Jesse Jackson And The Rainbow PUSH Coalition Should Support Sessions And Other Immigration Patriots
Qualified African-Americans are affected when IT employers hire foreign professionals instead of them.

Dallas Mavericks: Rick Carlisle on team's extended film session following Atlanta loss: 'Our untimely ...
The Mavericks had an extended film session on Thursday to go over what went wrong in the 98-95 loss to Atlanta on Wednesday.It was a laundry ...

Droid Life Q&A Sessions: Volume 35
It may be dead right now, but come January, there will be a whole lot happening in the Android world. With CES kicking off in early January, ...

Justin Bieber's Neck Tattoo Artist Spills Everything About His Late-Night Ink Session
Justin Bieber's Neck Tattoo Artist Spills Everything About His Late-Night Ink Session

Resources last updated: 12/23/2015 9:43:10 AM