Monday, March 26, 2012

setting session before postback

Greetings:

This web development is fun after you can see some progress. My current problem is that I want to set a session variable on button click which is also a postback. The session variable is not set, because it seems the post back takes place first. I could place ii in a text box first and then have another button act as a postback but this is just another click a user has to make. Can anyone suggest how to set the session and get the postback with one button click?

Ok, on the button click the browser will do the postback, just set

Button1_Click()

{

Session["mysession"] = "whateveryouwant";

}

However you are correct, the Page_Load will be called before Button1_Click() so wantever you want to do with the session do it inside the Button click even


I thought that is what I did but it didn't work . Here is the code that I used

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Session(

"cityname") = Cityddl.selectedvalueEndSub

End

Class

I should mention that I'm using a master page with this web page. Maybe that makes a difference.


sorry the copy didn't wotk. here is the actual code.

Protected

Sub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Session(

"cityname") = Cityddl.selectedvalueEndSub

End

Class
Are you facing any error? What do you mean it did not work?

Hi,

No I do not get an error. It just doesn't set the session. It just goes to the page back first without setting the session.

.


greetings,

It''s been my experience that when I don't get a good response on this forum, it's because I haven't adequately discribed my problem so I'm starting over. I,m using Visual web developer 2005 express edition and VB. I want to pass a value from a drop dropdownlist to another page. I'm also using master pages. I have a button that when pressed has this code.

.

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Session("cityname") = Cityddl.selectedvalue

EndSub

EndClass

This button also has a postback url to a target page. that needs the value of session("cityname"). My problem is that the postpack fires before the session command and the value of citydll.selectedvalue is not passed to the page. My question is, how can I make the session command work before the pageback command? There may be a command I can insert after the session code, something like "goto target page" but I am not aware of any command like that in this application or even if it is permisible to use in this situation. So I'm asking this very talented group to help me find a solution to my problem.


Since I haven't gotten a good response on this problem yet, I thought I'd let you see my problem. This is the web site I'm working on.www.classic-restaurants.com . I have to use a button to set the session variable and then another button to page back.. Makes it really sloppy. I would appreciate if anyone could let me know how to set the session variable before the page back or some other way to do this. I can do it with one button push when I'm not using a content page in a master page.
Thanks anyway guys and gals. I guess that some problems just don't have a solution.

0 comments:

Post a Comment