Monday, March 26, 2012

maintain session array variable

Hi all,
In the second web form, I have the following code: (The peopleinfo is a user
control which has name and ssn infomation, each field in this user control I
have set enableviewstate=true). I want to keep the peopleinfo control value
all there when customers click back or forth(continue). But my ctrlarr and
session("ctrlarr") was set up in submit_click sub, every time customer click
continue on the first page or click refresh on this page, the page is reload
and my data on this page are all gone. What should I do in this case?
Protected Peopleinfo0 As PeopleInfo
Protected Peopleinfo1 As PeopleInfo
Protected Peopleinfo2 As PeopleInfo
Protected Peopleinfo3 As PeopleInfo
Protected Peopleinfo4 As PeopleInfo
Protected Peopleinfo5 As PeopleInfo
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Submit1 As System.Web.UI.WebControls.Button
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Protected Sub Submit1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Submit1.Click
Dim ctrlarr(5) As PeopleInfo
Dim i As Integer
Dim errorFlag As Boolean = False
ctrlarr(0) = Peopleinfo0
ctrlarr(1) = Peopleinfo1
ctrlarr(2) = Peopleinfo2
ctrlarr(3) = Peopleinfo3
ctrlarr(4) = Peopleinfo4
ctrlarr(5) = Peopleinfo5
Label1.Text = ""
For i = 0 To 5
If ctrlarr(i).FirstName <> "" Then
If ctrlarr(i).LastName = "" Or ctrlarr(i).SSN = "" Then
Label1.Text &= "You need to complete information for
dependent " + ctrlarr(i).FirstName + " .<br>"
errorFlag = True
End If
End If
If ctrlarr(i).LastName <> "" Then
If ctrlarr(i).FirstName = "" Or ctrlarr(i).SSN = "" Then
Label1.Text &= "You need to complete information for
dependent " + ctrlarr(i).LastName + " .<br>"
If errorFlag = False Then
errorFlag = True
End If
End If
End If
If ctrlarr(i).SSN <> "" Then
If ctrlarr(i).FirstName = "" Or ctrlarr(i).LastName = "" Then
Label1.Text &= "You need to complete information for
dependent " + ctrlarr(i).SSN + " .<br>"
If errorFlag = False Then
errorFlag = True
End If
End If
End If
If ctrlarr(i).FirstName <> "" And ctrlarr(i).LastName <> "" And
ctrlarr(i).SSN <> "" Then
Session("depenFlag") = True
End If
Next
Session("ctrlarr") = ctrlarr
If errorFlag Then
For i = 0 To 5
Label1.Text &= ctrlarr(i).LastName + " " +
ctrlarr(i).FirstName + " " + ctrlarr(i).SSN + " .<br>"
Next
Else
Response.Redirect("EnrollReview.aspx")
End If
End Sub
BettyHi,
Does the session lost issue also happens in other controls? I mean those
default controls. If not, I think there should be something incorrect in
your custom control's design.
Does your custom control directly or indirectly inherits from
System.Web.UI.Page ?
If yes, please check your custom control's InitializeComponent method.
The Page.Init event should be wired up to the code which constructed your
Page
You should write which likes this (In C#):
this.Init += new System.EventHandler(this.Page_Init);
Thanks & Regards,
Neil Ni
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a w to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/te...erview/40010469
Others: https://partner.microsoft.com/US/te...upportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/defaul...rnational.aspx.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
Neil,
I am just Newbie for .net, please explain with our code. Here is my
usercontrol which is inherited from usercontrol. Don't understand what's you
r
meaning.
Public Class PeopleInfo
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
Protected WithEvents TxtSSN As System.Web.UI.WebControls.TextBox
Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TxtMI As System.Web.UI.WebControls.TextBox
Protected WithEvents PlanValidator As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents SSNValidator As
System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents LNameValidator As
System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents PlanList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents revalidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents reqvalidator2 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents reqSSNval As
System.Web.UI.WebControls.RequiredFieldValidator
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public Caption As String = "Dependent Information"
Private _ShowCaption As Boolean = True
Public Property ShowCaption() As Boolean
Get
Return _ShowCaption
End Get
Set(ByVal Value As Boolean)
_ShowCaption = value
End Set
End Property
Public Property FirstName() As String
Get
Return txtFirstName.Text
End Get
Set(ByVal Value As String)
txtFirstName.Text = Value
End Set
End Property
Public Property LastName() As String
Get
Return txtLastName.Text
End Get
Set(ByVal Value As String)
txtLastName.Text = Value
End Set
End Property
Public Property SSN() As String
Get
Return TxtSSN.Text
End Get
Set(ByVal Value As String)
TxtSSN.Text = Value
End Set
End Property
Public Property Plan() As String
Get
Return PlanList1.SelectedValue
End Get
Set(ByVal Value As String)
PlanList1.SelectedValue = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
End Class
Betty
"Neil Ni" wrote:

> Hi,
> Does the session lost issue also happens in other controls? I mean those
> default controls. If not, I think there should be something incorrect in
> your custom control's design.
> Does your custom control directly or indirectly inherits from
> System.Web.UI.Page ?
> If yes, please check your custom control's InitializeComponent method.
> The Page.Init event should be wired up to the code which constructed your
> Page
> You should write which likes this (In C#):
> this.Init += new System.EventHandler(this.Page_Init);
>
> Thanks & Regards,
> Neil Ni
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
=============
> Business-Critical Phone Support (BCPS) provides you with technical phone
> support at no charge during critical LAN outages or "business down"
> situations. This benefit is available 24 hours a day, 7 days a w to all
> Microsoft technology partners in the United States and Canada.
> This and other support options are available here:
> BCPS:
> https://partner.microsoft.com/US/te...erview/40010469
> Others: https://partner.microsoft.com/US/te...upportoverview/
> If you are outside the United States, please visit our International
> Support page:
> http://support.microsoft.com/defaul...rnational.aspx.
> ========================================
=============
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
Check my 10/24/2005 post
http://spaces.msn.com/sholliday/
You might want to create a PeopleInfoCollection ( : CollectionBase )
(implements CollectionBase) ...
and then persist this one collection object.
...
Using that wrapper object from the above url, I have no problems with
persisting objects.
"c676228" <bettys@.community.nospam> wrote in message
news:2D4644A4-F538-42AA-AA44-9AF2DFC713F1@.microsoft.com...
> Hi all,
> In the second web form, I have the following code: (The peopleinfo is a
user
> control which has name and ssn infomation, each field in this user control
I
> have set enableviewstate=true). I want to keep the peopleinfo control
value
> all there when customers click back or forth(continue). But my ctrlarr and
> session("ctrlarr") was set up in submit_click sub, every time customer
click
> continue on the first page or click refresh on this page, the page is
reload
> and my data on this page are all gone. What should I do in this case?
>
> Protected Peopleinfo0 As PeopleInfo
> Protected Peopleinfo1 As PeopleInfo
> Protected Peopleinfo2 As PeopleInfo
> Protected Peopleinfo3 As PeopleInfo
> Protected Peopleinfo4 As PeopleInfo
> Protected Peopleinfo5 As PeopleInfo
> Protected WithEvents Label1 As System.Web.UI.WebControls.Label
> Protected WithEvents Submit1 As System.Web.UI.WebControls.Button
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> End Sub
> Protected Sub Submit1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Submit1.Click
> Dim ctrlarr(5) As PeopleInfo
> Dim i As Integer
> Dim errorFlag As Boolean = False
> ctrlarr(0) = Peopleinfo0
> ctrlarr(1) = Peopleinfo1
> ctrlarr(2) = Peopleinfo2
> ctrlarr(3) = Peopleinfo3
> ctrlarr(4) = Peopleinfo4
> ctrlarr(5) = Peopleinfo5
>
> Label1.Text = ""
> For i = 0 To 5
> If ctrlarr(i).FirstName <> "" Then
> If ctrlarr(i).LastName = "" Or ctrlarr(i).SSN = "" Then
> Label1.Text &= "You need to complete information for
> dependent " + ctrlarr(i).FirstName + " .<br>"
> errorFlag = True
> End If
> End If
> If ctrlarr(i).LastName <> "" Then
> If ctrlarr(i).FirstName = "" Or ctrlarr(i).SSN = "" Then
> Label1.Text &= "You need to complete information for
> dependent " + ctrlarr(i).LastName + " .<br>"
> If errorFlag = False Then
> errorFlag = True
> End If
> End If
> End If
> If ctrlarr(i).SSN <> "" Then
> If ctrlarr(i).FirstName = "" Or ctrlarr(i).LastName = ""
Then
> Label1.Text &= "You need to complete information for
> dependent " + ctrlarr(i).SSN + " .<br>"
> If errorFlag = False Then
> errorFlag = True
> End If
> End If
> End If
> If ctrlarr(i).FirstName <> "" And ctrlarr(i).LastName <> ""
And
> ctrlarr(i).SSN <> "" Then
> Session("depenFlag") = True
> End If
> Next
>
> Session("ctrlarr") = ctrlarr
> If errorFlag Then
> For i = 0 To 5
> Label1.Text &= ctrlarr(i).LastName + " " +
> ctrlarr(i).FirstName + " " + ctrlarr(i).SSN + " .<br>"
> Next
> Else
> Response.Redirect("EnrollReview.aspx")
> End If
>
> End Sub
>
> --
> Betty
Hi Betty,
Please reference sloan's thread. I think it's a good solution.
Thanks & Regards,
Neil Ni
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a w to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/te...erview/40010469
Others: https://partner.microsoft.com/US/te...upportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/defaul...rnational.aspx.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

0 comments:

Post a Comment