|
-
Jan 6th, 2003, 11:59 AM
#1
Thread Starter
Lively Member
click the button twice ?
Hello everybody,
Can anyone please explain me a solution or workaround for my following problem ?
When I want to pass a session variable with a postback, then I always need to click the button twice ! 
Here's my code :
VB Code:
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.
Response.Write(Session("myTest"))
InitializeComponent()
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Session("myTest") = "testing"
End Sub
There's only one button on the page, nothing else ! I need to click twice the button before I can see testing ...
(it's with a postback)
I really don't know anymore how I can solve this !
Thanks in advance,
Bjorn
-
Jan 6th, 2003, 04:51 PM
#2
Make sure that the following are true:
In your @Page directive, autoeventwireup is false and that also, your button is autopostback=true.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Jan 6th, 2003, 05:08 PM
#3
One more thing:
Page load ALWAYS executes before any event handlers do. Therefore, if you are having a problem because you do not see your message onscreen until the second click, it's not a problem with clicking twice. It's because you are response.writing before you set the variable.
Page Loads first time:
Page Load executes, no session exists, blank output
Button is clicked:
Page Load executes, no session exists, blank output
Button Event Handler executes, session created, but not outputted since the PageLoad already executed before this step.
Button clicked again:
Page Load executes. Session exists this time, is outputted.
Button Event Handler executes again, session variable recreated.
You should make an ASP:Label and in both, the page load and the button event handler, change the .text property to reflect the value of that session variable.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Jan 6th, 2003, 06:06 PM
#4
Thread Starter
Lively Member
Hello Lord !
Thanks a lot ! Right now I understand why it didn't execute correctly and I also know a workaround now ! 
Thanks !
Originally posted by Lord_Rat
One more thing:
Page load ALWAYS executes before any event handlers do. Therefore, if you are having a problem because you do not see your message onscreen until the second click, it's not a problem with clicking twice. It's because you are response.writing before you set the variable.
Page Loads first time:
Page Load executes, no session exists, blank output
Button is clicked:
Page Load executes, no session exists, blank output
Button Event Handler executes, session created, but not outputted since the PageLoad already executed before this step.
Button clicked again:
Page Load executes. Session exists this time, is outputted.
Button Event Handler executes again, session variable recreated.
You should make an ASP:Label and in both, the page load and the button event handler, change the .text property to reflect the value of that session variable.
-
Jan 6th, 2003, 09:32 PM
#5
PowerPoster
That is funny. I was having the exact same problem with a part of my code. The funny thing is, I knew the order of events, and I still messed it up...lol. Thanks for the refresh...I needed it.
-
Jan 7th, 2003, 03:16 AM
#6
Thread Starter
Lively Member
I knew them too but I couldn't think about that first click that first the page loads and then you execute the click event....
But whatever ... I'm 26 and still got a long way to go ! (If Microsoft doesn't go tooooo fast )
Originally posted by hellswraith
That is funny. I was having the exact same problem with a part of my code. The funny thing is, I knew the order of events, and I still messed it up...lol. Thanks for the refresh...I needed it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|