Click here to Skip to main content
15,436,734 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
16/4/2011

Hi Steve, thanks for your article on the Web Service - I could nearly understand it (lol); I set up as illustrated and yep it worked. So now I have a great routine that lets me click a button and count the sessions (clicks), brilliant and I played for a while (about 4 clicks) then asked myself a question.. the question really... How in the name of all that is holy do I utilise this?

I have a textbox which contains 'user data', this data must be retained when the user clicks next page on an asp.net listview (forces a postback). Soooooo.. How do I say to the webservice (session variable) that the value of 'helloworld' is the content of the text box and on (after) postback the value of the textbox is the helloworld string. To maybe complicate things a bit more, the textbox is updated via a javascript (jquery) function so guess I would have to update the helloworld variable from that function?

I would really appreciate help. I've read / tried various methods for creating session variables on the fly, eg: fred = session('HelloWorld').ToString; but I just get namespace errors and am getting increasingly confused as well as stressed. THanks for reading this and hopefully my world will become illuminated by kind words of wisdom. Regards Raymond
Posted
Comments
Richard MacCutchan 16-Apr-11 7:53am    
Please post your question in the forum at the end of the article. There are nearly 8 million members of CodeProject so the chances of Steve seeing your message are not very high.
thatraja 16-Apr-11 10:02am     CRLF
Oh come on. Ask your question at the bottom of that article. BTW I hope I got him(Steve). Check the below URL for that article. http://www.codeproject.com/Articles/35119/Using-Session-State-in-a-Web-Service.aspx
[no name] 16-Apr-11 12:43pm    
I think the Oh come on is an extremely juvenile expression, I hope you don't use such a crass attitude when responding to questions. For your ignorant information I read the article, tried it etc. Found a few days later that I had some questions, could find the article again , saw 'ASK A QUESTION, so I did, but I wont bother in future if I'm going to get 'your sort of response'. Good day
thatraja 16-Apr-11 13:17pm     CRLF
Oh come on....(again) :) My reply is/was cool one always(you can check my other comments or answers too). Nothing rude.....honestly it just shows my tiredness on this weekend(Today I was in office :( ), that's all. Even I gave you the URL for that article for you. BTW my apologies if that reply hurt you, I didn't mean. Sorry Rain man.
[no name] 17-Apr-11 6:01am    
Accepted. Please understand that I or other users would not be aware of your - out of ills / sorts - mood and will take the nuance of things at read value. Regards. )I did appreciate the link which I turned into a pdf for future use as It was brilliant. BTW, I did try to post to the article, but even tho I was logged in that part would not activate).

1 solution

Whenever the post back happens, you should populate the session variable in the ASP.Net application. This is how you can do this:

// This should be done only once and you can check first if this session variable already exists
Session.Add("TextBoxText");

// This is how you add the variable text to the session object
Session["TextBoxText"] = yourTextBox.Text;

// To access the text later, use this
string textBoxText = Session["TextBoxText"].ToString();


To retain the values in the textbox when the user comes back to the page next time, you can check if the value is there in the session object:

if(Session["TextBoxText"] != null){
yourTextBox.Text = Session["TextBoxText"].ToString();
}


Now, to pass this value to the webservice, you will need to populate the appropriate property from the class that webservice exposes.

BTW, if you are referring to any article here at CP, it is better to post in the forum below the article so that the author gets notified.
 
Share this answer
 
Comments
[no name] 16-Apr-11 9:11am    
Hi. Thanks for the answer but it isn't working, due I'm sure to my stupidity. The first line of your solution isn't acceptable to VS2008, C#. It requiries a second value, Session.Add("TextBoxText"); Looking at examples it requires something like this: Session.Add("TextBoxText",TextBoxText); (or so the 47 examples I looked at one line, ie the second parameter should contain quotes - however VS2008, C# errs that too unless I contain the second value within quotes. Is it working now? I am lost even before I start. The remaining code I am assuming ought to be placed within the page load? I have so much on sessions but still I am not seeing the 'variable declaring and using process' clearly. The article I referred to was great, creating a HelloWorld public variable and returning a count on each page postback., so it all worked. TRouble is I dont want to return a count, I want to return a textbox.val and I cant see how to set that into the service. Why? beause for the webservice to be valid and operational the HelloWorld public variable has to contain and return a value! I cant see how to create a static webservice variable value that waits patiently to be populated. Setting up the service it 'demand's a return value and I can't see what to give it. I cannot find a single example of that, all examples return 'counts' or something calculated from within the Webservice its self which is not what I need to do. Any Advice (apart from give up!) would be helpful. Thanks Raymond
[no name] 16-Apr-11 12:44pm    
Thank you. I got it working once I placed the "" 's in and split the code into the 'right' sectinos. THank you for your help.
dan!sh 16-Apr-11 13:03pm    
Happy to help. Although you might be happier since you probably figured it on your own rather than some giving you code.
[no name] 16-Apr-11 13:19pm    
Could not have done it without your guidance which was clear, consise and extremely helpful. Yeh sure had to play around a bit, but hat slife and is more to do with my limited knowledge. Good luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900