Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

problem with session interacting between 2 webforms..

  Asked By: Muaz    Date: Nov 12    Category: Asp.net    Views: 928
  

I have 2 webforms called OrderPage and ArticlePage.

OrderPage is a dynamical datagrid, that grown by clicking on a "add new row" button
By clicking on this button, a datatable growns also (dataTable made in page_load of webform OrderPage

That DataGrid is also containing a button that when pushed redirect the page to ArticlePage
There i want to manipulate the tables of that DataSet...
So i put the dataSet into a Session and try to call it back in the 2nd webfrom ArticlePage,
Call it back is no problem, but the compiler says he don't know any of the tables made in the first webform OrderPage, while i did save it to the Session in the Page_Load...

I get this message:

The IListSource does not contain a data source named 'OrderTabel'.
my first application was exactly the same, unless i didn't redirect there and all controls were in 1 webform. There i had to put the visibility-style each time i changed, so it seems me more maintable to work with 2 webforms, interacting each other with the Redirect and the data in the DataSet...

Somebody knows where the problem is?
A Session seems me to be a "kind" (i know, with sessionid-cookie...) cookie so why can't i get those tables????



webform orderPage:

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
'Declareer een DataSet
Dim myDataSet As New DataSet()
'Declareer een DataTable OrderTabel die dan binnen die dataSet moet komen
Dim myDataTable As DataTable = New DataTable("OrderTabel")
'Voeg de kolommen van de DataTable in
myDataTable.Columns.Add("klantid", System.Type.GetType("System.String"))
myDataTable.Columns.Add("artikelid", System.Type.GetType("System.String"))
myDataTable.Columns.Add("anaam", System.Type.GetType("System.String"))
myDataTable.Columns.Add("prijs", System.Type.GetType("System.Double"))

myDataTable.Columns.Add("totaleprijs", System.Type.GetType("System.String"))
myDataTable.Columns.Add("datum", System.Type.GetType("System.DateTime"))
myDataTable.Columns.Add("aantal", System.Type.GetType("System.String"))
'Voeg de dataTable toe aan de dataSet
myDataSet.Tables.Add(myDataTable)

Dim objArray(6) As Object
'eerst blanco regel invoeren
objArray(0) = hiddenKlantID.Text
'klantid
objArray(1) = "-1"
'artikelid
objArray(2) = ""
'anaam
objArray(3) = "0"
'prijs
objArray(4) = "0"
'totale prijs
objArray(5) =
Date.Today() 'Datum
objArray(6) = ""
'Aantal
myDataTable.Rows.Add(objArray)


Dim myDropDownTable As DataTable = New DataTable("DDLTabel")
myDropDownTable.Columns.Add("aantal", System.Type.GetType("System.String"))
myDataSet.Tables.Add(myDropDownTable)

Dim objDataRow As DataRow
Dim x As Integer
For x = 1 To 10 Step 1
objDataRow = myDropDownTable.NewRow
objDataRow("aantal") = x
myDropDownTable.Rows.Add(objDataRow)
Next

Session("data") = myDataSet

DataGrid1.DataSource = myDataSet
DataGrid1.DataMember = "OrderTabel"
DataGrid1.DataBind()

End If
End Sub

Private
Sub handlesCommandsDataGrid1(ByVal objSender As System.Object, ByVal objArgs As DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
If objArgs.CommandSource.CommandName = "Kies" Then
Dim index = objArgs.Item.DataSetIndex
Dim myURL = ".\Articlepage.aspx?index=" & index
Response.Redirect(myURL)
End If

End Sub

Webform ArticlePage:

Private
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Declareer een DataSet
Dim myDataSet As New DataSet()

'Declareer een tweede DataTable ArtikelTabel die binnen dataSet moet komen
Dim myArtTable As DataTable = New DataTable("ArtikelTabel")

'Vul de ArtikelTabel via de SqlDataAdapter2
SqlDataAdapter1.Fill(myArtTable)
'voeg die ArtikelTabel toe aan de dataset
myDataSet.Tables.Add(myArtTable)


'Bind op een dataGrid
Session("data") = myDataSet
DataGrid2.DataSource = myDataSet
DataGrid2.DataMember = "ArtikelTabel"
DataGrid2.DataBind()

Dim mytabel = myDataSet.Tables("OrderTabel")
DataGrid3.DataSource = myDataSet
DataGrid3.DataMember = "OrderTabel"
DataGrid3.DataBind()

End If
End Sub

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Erma Henry     Answered On: Nov 12

Can I make a suggestion to everyone.

In each of Page_Load, Control_Load,  page  REnder, Control Render you write a "Response.Write" so that you can see th eevnets as they are firing.

What you will see is this - say you have a control in a page, in that control you have a button, which you click

pageload
controlload
buttonclick
pageprerender
controlprerender

do when you click the button  the event is fired after both the page and the control is loaded, so if you databind in there it doesn't show up until you postback again.
( its a pain in the ar*e I know)

So do your binding in pre_render.

I have done it all in page_load but it involved ViewState(which is like a session  but page specific, and rebinding.

Using pre-render is not cool. This is why :
Say you have a control which alters the html of its parent, then you may need to make changes in in pre_render.
But - if you have another control in that same page, with a button that makes a postback then IT needs to be bound in page_load of the parent (else we are a step behind).
So one defeats the other.

I recently had to do something where I was adding controls  programatically, I eventually had to split up what I was doing.

I had to add  a dummy control ( in pageload )


Controls.AddAt(0, blank)
Controls.AddAt(1, mycontrol)

Then in page render I had to
Controls.Remove(0)
Controls.AddAt(0, somecontrol)
Controls.AddAt(2,somecontrol2)
Controls.AddAt(3,somecontrol3)

where mycontrol was another control that had a button to postback.


You can see that at http://www.cardiffwebdesign.com

The whole thing is a page with 2 controls in it, the actual page being the base of it all, the menus, the images, etc. the content is added via a control.
The dropdown is one control and alters the parent pages html i.e. the menus. So this had to be done in page prerender ( since the dropdown control postsback after the page has already loaded)
The Bits with all the writing on it is the other control I mentioned, to make a postback work  it had to be done in pageload.

And I had to keep the order of adding the controls - but later additions had to be done in pre_render whilst earlier ones in page_load. Hence the removeAt came in very handy - essential in fact.

Note the menu at the above url, improved GotDotNEtMenu's - call  'em GotDotNEtMultMenus - altered so you can have as many as you want in a single page. Cool eh ?
Think I'll release them when I've finished them.

I know, i know, I know  ... kinda resembles GotDotNet in general eh ? ( I'm a programmer not a designer ! - I'm just waiting for the law suit ! )

Soz guys - ain't giving the code or html away - it took ages. But will help if I can. Its just a case of mess about with it trying your hardest NOT to use pre_render unless you really have to.

 
Didn't find what you were looking for? Find more on problem with session interacting between 2 webforms.. Or get search suggestion and latest updates.




Tagged: