How can I grab the Primary Key of a record just submitted in MultiView1 and use it as part of the data submitted in MultiView2 of a Web Form?
I'm currently generating my own primary key on Page_Load then sticking it in the the next part of the for to use as a Foreign Key in a related table.
I know this is a bad way to do it. That's why I'm looking for a better way.
There are actually three related tables: Employers, Worksites and JobTitles. Each with a OTM relationship with the next down the line. e.g. One employer will have multiple worksites and each worksite will have multiple job titles.
What happens is, an employer fills out a job order requesting one or more worksites and one or more job titles for each site, so they are filling out a three part form (I'm using a MultiView).
I'm sure there is a better way. I can post more code if necessary.
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If Not IsPostBack Then
If txtPriKeyEmployerID.Text = "" Then
'Create a new Random class in VB.NET
Dim RandomClass As New Random()
'Generate a random "Primary Key" for the Employers table between 1000000 and 9999999
Dim priKeyEmployers As Integer
priKeyEmployers = RandomClass.Next(1000000, 9999999)
txtPriKeyEmployerID.Text = priKeyEmployers ' Put Employers Primary Key in Employer ID# TextBox on Employer Form
txtForeignKeyWsEmployerID.Text = priKeyEmployers ' Put Employers Primary Key in Employer ID# TextBox on Worksite Form
txtForeignKeyPosEmployerID.Text = priKeyEmployers ' Put Employers Primary Key in Employer ID# TextBox on Position Form