473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

using Session variables for arraylist in TEXTBOXES

hi.. I am new to vb.net i am doing a program using dynamic textboxes which involves two pages .. where values of textboxes in one page must be transfered to to other sex of textboxes in another page, . please help me .. I tried using session variables but its not working.. this s my code..

PAGE 1
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
  2.  
  3. nval2 = TextBox2.Text
  4.  
  5.             If numofper > nval2 Then
  6.                 Session("a1") = textdynamic5
  7.                 SessionHandler.keynval2 = nval2
  8.                 Response.Redirect("fortpage.aspx")
  9.  
  10.             Else
  11.                 MsgBox("'n' value must be less than Number of Periods")
  12.             End If
  13.  
  14.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  15.  
  16. If Session("weights") = True Then
  17.             ReDim TxtDyn5(nval2)
  18.             Button4.EnableViewState = True
  19.             Button4.ID = "btn4"
  20.             For m As Integer = 0 To nval2 - 1
  21.                 TxtDyn5(m) = New TextBox
  22.                 TxtDyn5(m).EnableViewState = True
  23.                 Panel4.Controls.Add(TxtDyn5(m))
  24.                 textdynamic5.Add(textdynamic5)
  25.                 TxtDyn5(m).Width = 60
  26.  
  27.             Next
  28.             Session("a1") = True
  29.         End If
  30.  
  31.  
  32.     End Sub
  33.  
  34.  
PAGE 2
Expand|Select|Wrap|Line Numbers
  1. Dim textdynamic5 As New ArrayList
  2.     Dim TxtDyn5 As TextBox()
  3.  
  4.  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.  
  6. Dim textdynamic5 As ArrayList = CType(HttpContext.Current.Session("a1"), ArrayList)
  7.  
  8.  ElseIf Session("WMA") = True Then
  9.             Label4.Text = "WEIGHTED MOVING AVERAGE"
  10.  
  11.             Dim nval2 As String = SessionHandler.keynval2
  12.             Label6.Text = "" + nval2
  13.             Label7.Text = "Value of 'n'"
  14.             Label8.Text = "Weights"
  15.             If Session("weights") = True Then
  16.  
  17.                 ReDim TxtDyn5(nval2)
  18.                 textdynamic5 = Session("a1")
  19.                 For m As Integer = 0 To nval2 - 1
  20.                     TxtDyn5(m) = New TextBox
  21.                     TxtDyn5(m).EnableViewState = True
  22.                     Panel14.Controls.Add(TxtDyn5(m))
  23.                     textdynamic5.Add(textdynamic5)
  24.                     TxtDyn5(m).Width = 60
  25.  
  26.                 Next
  27.  
  28.             End If
  29. end sub
  30.  
please temme wher im goin wrong..
Oct 28 '08 #1
8 2879
adarshyam,

I didn't look at your code, but I will give you the first place to look when troubleshooting controls that were added dynamically.

When you add controls dynamically, remember that you have to recreate the controls on postback specifically in OnInit in order to have the ViewState for those controls loaded (ViewState should contain your textbox values that the user typed). So viewstate should be turned on for those controls, and the ID property for each control must be the same when you add it on Page_Load, and recreate/readd it on OnInit.

Hope that helps.
Oct 29 '08 #2
thank u v much for your reply.. i have one more doubt.. while recreating the controls in next page can i use same name to those controls? and should i keep the arraylist also in session and get back in next page? if so can u pls temme how..
Oct 30 '08 #3
Frinavale
9,735 Expert Mod 8TB
thank u v much for your reply.. i have one more doubt.. while recreating the controls in next page can i use same name to those controls?
Sure!
This is probably advisable because it'll help you understand what is what.

What I don't understand is why you need to name the controls if they are in an arraylist??


and should i keep the arraylist also in session and get back in next page? if so can u pls temme how..
Check out the article on how to use dynamic controls in ASP.NET

-Frinny
Oct 30 '08 #4
ok i ve refined my question tis tym :)

i need to bring the values of textboxes from page1 to page2

page1

' i ve created textboxes using a button n put the textboxes in viewstate in pageload with same ID. i ve given the session of arraylist in the goto next page button

pageload
Expand|Select|Wrap|Line Numbers
  1.         If Session("weights") = True Then
  2.     Dim textdynamicwt As New ArrayList()
  3.     Dim TxtDynwt As TextBox()
  4.             ReDim TxtDynwt(nval2)
  5.             Button4.EnableViewState = True
  6.             Button4.ID = "btn4"
  7.             For m As Integer = 0 To nval2 - 1
  8.                 TxtDynwt(m) = New TextBox
  9.                 TxtDynwt(m).EnableViewState = True
  10.                 Panel4.Controls.Add(TxtDynwt(m))
  11.                 textdynamicwt.Add(textdynamicwt)
  12.                 TxtDynwt(m).Width = 60
  13.                 TxtDynwt(m).ID = "TxtDynwt_" & m
  14.             Next
  15.  
  16.         End If
  17.  
button(goto next page)
Expand|Select|Wrap|Line Numbers
  1.          If Session("weights") = True Then
  2.          Session("txtdyn") = textdynamicwt
  3.  
page 2

' i ve created dyn textboxes again and retrieved arraylist from session

pageload
Expand|Select|Wrap|Line Numbers
  1.  
  2.    textdynamicwt = Session("txtdyn")
  3.             If Session("weights") = True Then
  4.    Dim textdynamicwt As New ArrayList
  5.    Dim TxtDynwt As TextBox()
  6.                 ReDim TxtDynwt(nval2)
  7.                 For m As Integer = 0 To nval2 - 1
  8.                     TxtDynwt(m) = New TextBox
  9.                     TxtDynwt(m).EnableViewState = True
  10.                     Panel14.Controls.Add(TxtDynwt(m))
  11.                     textdynamicwt.Add(textdynamicwt)
  12.                     TxtDynwt(m).Width = 60
  13.                     TxtDynwt(m).ID = "TxtDynwt_" & m
  14.                 Next
  15.             End If
  16.  
Now my problem is i can see only empty textboxes in page2 i cant get the values that i entered in the textboxes in page1. please help me with a solution i am trying this for the past two days.. im very new to vb.net...
Oct 31 '08 #5
Frinavale
9,735 Expert Mod 8TB
Did you read the article on how to use dynamic controls that I posted earlier?
You cannot add your TextBoxes to the page in the PageLoad event. You have to do that in the OnInit event....

Please read the article for why.
This will explain why you aren't getting any text values.

In the future please remember to use code tags when posting code snippets.

-Frinny
Oct 31 '08 #6
sorry i forgot to use code tags and thanks for the guidance..
Oct 31 '08 #7
frinny,
can you please send me the link for the article u were talkin about..i couldnt find it in the forum.. i see webform_Init event.. is that the same as OnInit??
Oct 31 '08 #8
Curtis Rutland
3,256 Expert 2GB
Here's Frinny's article:
http://bytes.com/forum/thread750415.html
Nov 1 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve Remer | last post by:
My application (relevant code snippets below) originally used Session variables in order to maintain state from page to page. After being unable to solve the mystery of why those variables were...
31
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily...
2
by: dana lees | last post by:
Hello, I am using session variables in a cs class file. I am inserting a sortedList to a session variable like this: System.Web.HttpContext.Current.Session = EventsSortedList; Later on,...
1
by: VMI | last post by:
When my webpage loads the first time, I fill my datatable with records from the DB and display them in my gridview. Once it loads, the user clicks on a button and add records to the datatable,...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
by: SLG31 | last post by:
I'm designing like a shopping cart and have a product list which is an xml file consisting of products and prices which is loaded into a dataset then bound to a datagrid There are buttons next to...
2
by: moorcroft | last post by:
Hi, I'm developing a web application using ASP .Net and C# as code behind. On my home page Index.aspx I have login textbox's so if you correctly enter your username and password it says "You have...
3
by: Mark Rae [MVP] | last post by:
"Lloyd Sheen" <a@b.cwrote in message news:uL5TPXPvIHA.1688@TK2MSFTNGP06.phx.gbl... Surely that will throw an exception because you're trying to populate a DataSet variable with an object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.