HiI'm getting no response to session variables, viewstate variables or values held in a hidden textbox when the form performs a postback. As an example I am creating a session variable on a button click just before sending a mail within the same button click
event. Session("sentm")="y" - then in the ispostback event I am trying to use the session value but the value returns empty (null). I know that thesession value was set because as a test after I set it, I set a label to the session value and the Label.Text
gets updated correctly - but as I stated above on the ispostback event when I call the Dim str As String = Session("sentm").ToString() I get a null value. The same happens with viewstate and also if I try to get the value of a hidden textbox which I also tried
setting within the button click event, all three values are returned as null. I'm fairly new to Asp.Net and I suspect it will be some thing stupid, something I have to 'switch' on/off but I cant see what. I have a demo on another page within the same site
and that carries a session over to a new page and the new page is able to use it ok.So I know it isn't anything with the web.config file. Any ideas? The imports I am usingImports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security
Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Collections.Generic Imports System.Data.SqlClient Imports System.Data.Common Imports System Imports System.Globalization
Imports System.Reflection Imports System.Drawing Imports System.Web.Services Imports System.Text Imports System.Net.Mail Imports System.IO Imports System.CollectionsThanks in advance for any pearls of wisdom.
You said you are a newbie for asp.net. So I decide to create a simple sample code to demonstrate how to set and get ASP.NET Session, ViewState and Hidden Field:
Note: you firstly need to set the Session/ViewState/Hidden Field. And then retrieve their value and generally, when we get the Session/ViewState/Hidden Field, we always call if statement to determine whether they are null, this can help me to avoid the exception:
Partial Class Default3
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("name") = TextBox1.Text
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If Session("name") IsNot Nothing Then
Label1.Text = Session("name")
End If
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
ViewState("name") = TextBox1.Text
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
If ViewState("name") IsNot Nothing Then
Label1.Text = ViewState("name")
End If
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
HiddenField1.Value = TextBox1.Text
End Sub
Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
If HiddenField1 IsNot Nothing Then
Label1.Text = HiddenField1.Value
End If
End Sub
End Class
Just copy sample sample code to test, and you can find more information from the similar thread I provided previously.
And question please feel free to post them.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Thank you very much for the reply, and for the time taken to compile it for me. I will of course retain it as an example for when I tear my hair our again with this issue. Your example functions perfectly and the session state example is how I was using
it on the page concerned - and although I have checked my session delcaration against your example so that I 'know' that what I am doing is correct the page in question still returns a null session. Like I said before on other pages the session carries through as
expected, hence being stumped. The idea was to confirm that a mail had been sent and that was the reason for the 'postback because within the page I have a script call to run a jQuery script after the mail had gone, but I didn't want that script to run if
the had page posted back for another reason. The reason for that need is because the contact form as such is actually a pop up form situated on the page along with other elements and several of the other elements might cause a post back - they shouldn't but
this was a belt and braces approach to make certain that the page behaved correctly at all times - so I needed to isolate the 'call' to make sure that the page acted appropriately. But, that said, at least I know from your examples whether my declarations
are correct - or not :) - and that is a brilliant start so now all I have to do is remove elements one by one and see if I can isolate the why to the problem. Thanks again. regards
I've isolated the cause of my problem which is; I am setting the session variable to 'y' on the button click which then sends the mail.
I was then attempting via the ispostback on the page load to confirm that the postback occured as a result of the button click to send the mail or if the postback occurred because of another action within the webform.
I believe - and I have tested this idea too - that the button actually doesn't register as a post back but rather , it causes a submit action.
Visually the submit action the same effect as a postback in so much as my contact form closed because the page state returned to the orignal onload state. To stop that I added script function to reopen the contact page, display thank you to the user and
then gracefully close.
All that works fine, but because the button does not register a postback event my way of trying to trap exactly what caused the postback (I wanted to be certain that the thank you script only ran on the mail send button click) I cannot test the sender that
way. If you are interested in seeing what I mean by the form contact action you can click my website in my profile and it will take you to the page concerned where you can see the contact form working (click contact at the top of the page) .
So at least I now know why I am not collecting the session variable value on the ispostback - simply because there is no postback. Ho hum. thank you for your time and energy. kind regards
Thanks to your example I Solved it. Once I stopped worrying, lol, I placed this example code on every stage of the page life cycle:
If IsPostBack
Then
If
Session("name")
IsNotNothingThen
TextBox2.Text = Session("name")
EndIf
Label2.text = Session("name")
+ "
page Init"
EndIf
The save session obviously returned a value and the prerender returned a value but the other stages returned only the + value I added, the session value was not returned although we know that it exists - so I placed my script call in the prerender stage
of the page cycle and achieved what I wanted.
I still have to go away and read to understand why after a button click the prerender accepts a postback argument, but that the init, initcomplete, preload and the load stages of the page cycle do not? I( did read somewhere that a button doesnt actually
cause a postback, rather that it causes a submit action which in the life cycle of a page is interpretated somewhat differently?). Still I am learning. Thanks for your help. Hope this might help someone else sometime.
Marked as answer by rayh1955 on May 14, 2012 01:15 PM
What I did as a test was to take your code and add a few more simple functions on the savesession, prerender, init etc stages of the page life cycle as per below and then ran it. When a stage returned a value into textbox 2 I remmed it out until I reached a part where the session variable was no longer returned which on this test was the init stage.
life
Partial Class sessiontest
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("name") = TextBox1.Text
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If Session("name") IsNot Nothing Then
Label1.Text = Session("name")
End If
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
ViewState("name") = TextBox1.Text
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
If ViewState("name") IsNot Nothing Then
Label1.Text = ViewState("name")
End If
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
HiddenField1.Value = TextBox1.Text
End Sub
Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
If HiddenField1 IsNot Nothing Then
Label1.Text = HiddenField1.Value
End If
End Sub
Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox2.Text = Session("name")
End If
Label2.Text = Session("name") + " page Init"
End If
End Sub
Protected Sub Page_InitComplete(sender As Object, e As EventArgs) Handles Me.InitComplete
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox2.Text = Session("name")
End If
Label2.Text = Session("name") + " initcomplete"
End If
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox2.Text = Session("name")
End If
Label1.Text = Session("name") + " load"
End If
End Sub
Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox2.Text = Session("name")
End If
Label2.Text = Session("name") + " prerender"
End If
End Sub
Protected Sub Page_SaveStateComplete(sender As Object, e As EventArgs) Handles Me.SaveStateComplete
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox2.Text = Session("name") + " savestate"
End If
Label2.Text = Session("name") + " savestate"
End If
End Sub
End Class
If all above are your full source code. Then just my sample code is enough. Don't need to add Init, InitComplete and PreRender event on your code behind. Now I suggest you to create new web site project and create a simple web page with my sample code to
test again whether the session still is null.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Thanks for your reply. The code I sent, based on yours with my additions, was my test. Maybe my explanation was a bit confusing. I added the page load events to see where within the page load events the session stopped being picked up as that was the point
of my initial question- your example works well until you try to pick up a value within a page load cycle. If you run the code I added you will see what I mean. The page load events only allow me to collect the session variable value upto the pre render stage,
after that for some reason using a 'ispostback' check fails to retrieve the session variable although of course it is still active. As I said, the code I supplied does I think illustrate that.
It seems to me that picking up a session variable during a page load life cycle is only possible at the pre render stage - after that stage even your example failed to return the variable value that was set via your button click routimes. Either the code
I was using to trap the value - example being anyone of the functions I added - is flawed or that the page does not allow the session variable to be grabbed as a variable to 'question' after the prerender stage. As you will notice after the prerender stage
textbox 2 and the lbel 2 fail to display the session value 'name'. It is this confusion that I was trying to understand. Thanks for your time
As you will notice after the prerender stage textbox 2 and the lbel 2 fail to display the session value 'name'. It is this confusion that I was trying to understand.
You mean you couldn't get the session variable at the SaveStateComplete stage? I test this, and I can get the session variable:
Partial Class Default4
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("name") = TextBox1.Text
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If Session("name") IsNot Nothing Then
Label1.Text = Session("name")
End If
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
ViewState("name") = TextBox1.Text
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
If ViewState("name") IsNot Nothing Then
Label1.Text = ViewState("name")
End If
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
HiddenField1.Value = TextBox1.Text
End Sub
Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click
If HiddenField1 IsNot Nothing Then
Label1.Text = HiddenField1.Value
End If
End Sub
Protected Sub Page_SaveStateComplete(ByVal sender As Object, ByVal e As EventArgs) Handles Me.SaveStateComplete
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox1.Text = Session("name") + " savestate"
End If
Label1.Text = Session("name") + " savestate"
End If
End Sub
End Class
Please mark the replies as answers if they help or unmark if not.
Feedback to us
RayH1955
Member
99 Points
42 Posts
session variable, viewstare variable and hidden field return null values
May 07, 2012 03:58 AM|LINK
HiI'm getting no response to session variables, viewstate variables or values held in a hidden textbox when the form performs a postback. As an example I am creating a session variable on a button click just before sending a mail within the same button click event. Session("sentm")="y" - then in the ispostback event I am trying to use the session value but the value returns empty (null). I know that thesession value was set because as a test after I set it, I set a label to the session value and the Label.Text gets updated correctly - but as I stated above on the ispostback event when I call the Dim str As String = Session("sentm").ToString() I get a null value. The same happens with viewstate and also if I try to get the value of a hidden textbox which I also tried setting within the button click event, all three values are returned as null. I'm fairly new to Asp.Net and I suspect it will be some thing stupid, something I have to 'switch' on/off but I cant see what. I have a demo on another page within the same site and that carries a session over to a new page and the new page is able to use it ok.So I know it isn't anything with the web.config file. Any ideas? The imports I am usingImports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Collections.Generic Imports System.Data.SqlClient Imports System.Data.Common Imports System Imports System.Globalization Imports System.Reflection Imports System.Drawing Imports System.Web.Services Imports System.Text Imports System.Net.Mail Imports System.IO Imports System.CollectionsThanks in advance for any pearls of wisdom.
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: session variable, viewstare variable and hidden field return null values
May 14, 2012 03:50 AM|LINK
Hi,
I note you have post a similar thread about this topic:
http://forums.asp.net/p/1800756/4978761.aspx/1?p=True&t=634725487112450049
You said you are a newbie for asp.net. So I decide to create a simple sample code to demonstrate how to set and get ASP.NET Session, ViewState and Hidden Field:
Note: you firstly need to set the Session/ViewState/Hidden Field. And then retrieve their value and generally, when we get the Session/ViewState/Hidden Field, we always call if statement to determine whether they are null, this can help me to avoid the exception:
Asps file:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Set Session" /> <asp:Button ID="Button2" runat="server" Text="GetAndDispalySession" /> </div> <br /> <asp:Button ID="Button3" runat="server" Text="SetViewState" /> <asp:Button ID="Button4" runat="server" Text="GetAndDisplayViewState" /> <br /> <br /> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:Button ID="Button5" runat="server" Text="SetHiddenField" /> <asp:Button ID="Button6" runat="server" Text="GetAndDispalyHiddenField" /> <br /> </form> </body> </html>Code behind:
Partial Class Default3 Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Session("name") = TextBox1.Text End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click If Session("name") IsNot Nothing Then Label1.Text = Session("name") End If End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click ViewState("name") = TextBox1.Text End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click If ViewState("name") IsNot Nothing Then Label1.Text = ViewState("name") End If End Sub Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click HiddenField1.Value = TextBox1.Text End Sub Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click If HiddenField1 IsNot Nothing Then Label1.Text = HiddenField1.Value End If End Sub End ClassJust copy sample sample code to test, and you can find more information from the similar thread I provided previously.
And question please feel free to post them.
Feedback to us
Develop and promote your apps in Windows Store
RayH1955
Member
99 Points
42 Posts
Re: session variable, viewstare variable and hidden field return null values
May 14, 2012 09:05 AM|LINK
Hi Mamba
Thank you very much for the reply, and for the time taken to compile it for me. I will of course retain it as an example for when I tear my hair our again with this issue. Your example functions perfectly and the session state example is how I was using it on the page concerned - and although I have checked my session delcaration against your example so that I 'know' that what I am doing is correct the page in question still returns a null session. Like I said before on other pages the session carries through as expected, hence being stumped. The idea was to confirm that a mail had been sent and that was the reason for the 'postback because within the page I have a script call to run a jQuery script after the mail had gone, but I didn't want that script to run if the had page posted back for another reason. The reason for that need is because the contact form as such is actually a pop up form situated on the page along with other elements and several of the other elements might cause a post back - they shouldn't but this was a belt and braces approach to make certain that the page behaved correctly at all times - so I needed to isolate the 'call' to make sure that the page acted appropriately. But, that said, at least I know from your examples whether my declarations are correct - or not :) - and that is a brilliant start so now all I have to do is remove elements one by one and see if I can isolate the why to the problem. Thanks again. regards
RayH1955
Member
99 Points
42 Posts
Re: session variable, viewstare variable and hidden field return null values
May 14, 2012 10:56 AM|LINK
Hi Mamba
I've isolated the cause of my problem which is; I am setting the session variable to 'y' on the button click which then sends the mail.
I was then attempting via the ispostback on the page load to confirm that the postback occured as a result of the button click to send the mail or if the postback occurred because of another action within the webform.
I believe - and I have tested this idea too - that the button actually doesn't register as a post back but rather , it causes a submit action.
Visually the submit action the same effect as a postback in so much as my contact form closed because the page state returned to the orignal onload state. To stop that I added script function to reopen the contact page, display thank you to the user and then gracefully close.
All that works fine, but because the button does not register a postback event my way of trying to trap exactly what caused the postback (I wanted to be certain that the thank you script only ran on the mail send button click) I cannot test the sender that way. If you are interested in seeing what I mean by the form contact action you can click my website in my profile and it will take you to the page concerned where you can see the contact form working (click contact at the top of the page) .
So at least I now know why I am not collecting the session variable value on the ispostback - simply because there is no postback. Ho hum. thank you for your time and energy. kind regards
Raymond
RayH1955
Member
99 Points
42 Posts
Re: session variable, viewstare variable and hidden field return null values
May 14, 2012 01:15 PM|LINK
Hi Mamba, again.
Thanks to your example I Solved it. Once I stopped worrying, lol, I placed this example code on every stage of the page life cycle:
If IsPostBack Then
If Session("name") IsNot Nothing Then
TextBox2.Text = Session("name")
End If
Label2.text = Session("name") + " page Init"
End If
The save session obviously returned a value and the prerender returned a value but the other stages returned only the + value I added, the session value was not returned although we know that it exists - so I placed my script call in the prerender stage of the page cycle and achieved what I wanted.
I still have to go away and read to understand why after a button click the prerender accepts a postback argument, but that the init, initcomplete, preload and the load stages of the page cycle do not? I( did read somewhere that a button doesnt actually cause a postback, rather that it causes a submit action which in the life cycle of a page is interpretated somewhat differently?). Still I am learning. Thanks for your help. Hope this might help someone else sometime.
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: session variable, viewstare variable and hidden field return null values
May 15, 2012 02:59 AM|LINK
Well, I don't recommend this. Maybe you can post you full source code, and I will do some research for it to find what cause leads to session to null.
Feedback to us
Develop and promote your apps in Windows Store
RayH1955
Member
99 Points
42 Posts
Re: session variable, viewstare variable and hidden field return null values
May 15, 2012 06:23 AM|LINK
Partial Class sessiontest Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Session("name") = TextBox1.Text End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click If Session("name") IsNot Nothing Then Label1.Text = Session("name") End If End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click ViewState("name") = TextBox1.Text End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click If ViewState("name") IsNot Nothing Then Label1.Text = ViewState("name") End If End Sub Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click HiddenField1.Value = TextBox1.Text End Sub Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click If HiddenField1 IsNot Nothing Then Label1.Text = HiddenField1.Value End If End Sub Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init If IsPostBack Then If Session("name") IsNot Nothing Then TextBox2.Text = Session("name") End If Label2.Text = Session("name") + " page Init" End If End Sub Protected Sub Page_InitComplete(sender As Object, e As EventArgs) Handles Me.InitComplete If IsPostBack Then If Session("name") IsNot Nothing Then TextBox2.Text = Session("name") End If Label2.Text = Session("name") + " initcomplete" End If End Sub Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If IsPostBack Then If Session("name") IsNot Nothing Then TextBox2.Text = Session("name") End If Label1.Text = Session("name") + " load" End If End Sub Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender If IsPostBack Then If Session("name") IsNot Nothing Then TextBox2.Text = Session("name") End If Label2.Text = Session("name") + " prerender" End If End Sub Protected Sub Page_SaveStateComplete(sender As Object, e As EventArgs) Handles Me.SaveStateComplete If IsPostBack Then If Session("name") IsNot Nothing Then TextBox2.Text = Session("name") + " savestate" End If Label2.Text = Session("name") + " savestate" End If End Sub End ClassMamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: session variable, viewstare variable and hidden field return null values
May 16, 2012 08:01 AM|LINK
Hi,
If all above are your full source code. Then just my sample code is enough. Don't need to add Init, InitComplete and PreRender event on your code behind. Now I suggest you to create new web site project and create a simple web page with my sample code to test again whether the session still is null.
Feedback to us
Develop and promote your apps in Windows Store
RayH1955
Member
99 Points
42 Posts
Re: session variable, viewstare variable and hidden field return null values
May 16, 2012 09:04 AM|LINK
Hi Mamba
Thanks for your reply. The code I sent, based on yours with my additions, was my test. Maybe my explanation was a bit confusing. I added the page load events to see where within the page load events the session stopped being picked up as that was the point of my initial question- your example works well until you try to pick up a value within a page load cycle. If you run the code I added you will see what I mean. The page load events only allow me to collect the session variable value upto the pre render stage, after that for some reason using a 'ispostback' check fails to retrieve the session variable although of course it is still active. As I said, the code I supplied does I think illustrate that.
It seems to me that picking up a session variable during a page load life cycle is only possible at the pre render stage - after that stage even your example failed to return the variable value that was set via your button click routimes. Either the code I was using to trap the value - example being anyone of the functions I added - is flawed or that the page does not allow the session variable to be grabbed as a variable to 'question' after the prerender stage. As you will notice after the prerender stage textbox 2 and the lbel 2 fail to display the session value 'name'. It is this confusion that I was trying to understand. Thanks for your time
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: session variable, viewstare variable and hidden field return null values
May 17, 2012 03:37 AM|LINK
Hi,
Sorry I'm still confused about your comments.
You mean you couldn't get the session variable at the SaveStateComplete stage? I test this, and I can get the session variable:
Partial Class Default4 Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Session("name") = TextBox1.Text End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click If Session("name") IsNot Nothing Then Label1.Text = Session("name") End If End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click ViewState("name") = TextBox1.Text End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click If ViewState("name") IsNot Nothing Then Label1.Text = ViewState("name") End If End Sub Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click HiddenField1.Value = TextBox1.Text End Sub Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click If HiddenField1 IsNot Nothing Then Label1.Text = HiddenField1.Value End If End Sub Protected Sub Page_SaveStateComplete(ByVal sender As Object, ByVal e As EventArgs) Handles Me.SaveStateComplete If IsPostBack Then If Session("name") IsNot Nothing Then TextBox1.Text = Session("name") + " savestate" End If Label1.Text = Session("name") + " savestate" End If End Sub End ClassFeedback to us
Develop and promote your apps in Windows Store