FormView Insert Session value  
Author Message
keezwyner





PostPosted: Wed Apr 16 19:37:13 CDT 2008 Top

ASP.Net >> FormView Insert Session value

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

Web Programming121  
 
 
d-42





PostPosted: Wed Apr 16 19:37:13 CDT 2008 Top

ASP.Net >> FormView Insert Session value
> 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