FormView Insert Session value

D

d-42

Hi,

I'm trying to use FormView to Insert an Object to an ObjectDataSource.

The insert method signature is simply:

void DALObject.InsertPerson(Person myObject)

The person object for the sake of argument is:

class Person {
// properties:
string FirstName // self explanatory
string LastName
long PersonID // "identity" (set by the database)
long AccountID // a related account id, needs to be set
}

The formview collects first name, last name, etc, and when I hit
insert, it automagically creates a Person object with the bound fields
set..

<InsertItemTemplate>
First Name: <asp:TextBox ID="tbFirstNAme" runat="server"
Text='<%# Bind("FirstName") %>' /><br />
...etc for lastname, then buttons, etc...
</InsertItemTemplate>

But one of the fields I need set is a session variable that contains
the AccountID to use.

How do I get it to create the object to be inserted and assign the
AccountID to the session variable. An additional constraint is that I
do not want the AccountID to be visible on the page.

I'm stumped.

The only thing I've thought of is to catch the OnInsertingEvent, but
I'm not even really sure what to do with it. It doesn't give me the
Person object its going to insert... just a dictionary of Property and
Value pairs for the Person it will create to insert. I might be able
to manually add a key pair ... to the dictionary? {AccountID,
session"AccountID" } ?? Would that work? It seems pretty clumsy...

Surely there is a better way?

Thanks,
Dave
 
D

d-42

Hi,

I'm trying to use FormView to Insert an Object to an ObjectDataSource.

The insert method signature is simply:

void DALObject.InsertPerson(Person myObject)

The person object for the sake of argument is:

class Person {
// properties:
string FirstName // self explanatory
string LastName
long PersonID // "identity" (set by the database)
long AccountID // a related account id, needs to be set

}

The formview collects first name, last name, etc, and when I hit
insert, it automagically creates a Person object with the bound fields
set..

<InsertItemTemplate>
First Name: <asp:TextBox ID="tbFirstNAme" runat="server"
Text='<%# Bind("FirstName") %>' /><br />
...etc for lastname, then buttons, etc...
</InsertItemTemplate>

But one of the fields I need set is a session variable that contains
the AccountID to use.

How do I get it to create the object to be inserted and assign the
AccountID to the session variable. An additional constraint is that I
do not want the AccountID to be visible on the page.

I'm stumped.

The only thing I've thought of is to catch the OnInsertingEvent, but
I'm not even really sure what to do with it. It doesn't give me the
Person object its going to insert... just a dictionary of Property and
Value pairs for the Person it will create to insert. I might be able
to manually add a key pair ... to the dictionary? {AccountID,
session"AccountID" } ?? Would that work? It seems pretty clumsy...

Surely there is a better way?

Thanks,
Dave

Follow up... for the record, manually adding a key pair to the
dictionary in the onInsertingEvent DOES work, but I still think its
clumsy... and would like to know if there is a better way?

Thanks again,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top