Link to home
Start Free TrialLog in
Avatar of Michael Sterling
Michael SterlingFlag for United States of America

asked on

How do I do a simple POST and GET in C# to pass/retrieve values?

I'm used to being able to use session variables or (in an older application) the authentication provided by ASP .NET to control security/access within my web app. Now, for a couple of reasons, I need to POST and GET data between pages but I'm struggling with how this is done. I need a simple way,using C#, to POST some data from one page and then GET (process/retrieve) it on another page. Can someone provide me with simple clear examples or code for how this is done? I'm using VS 2012 and 2015.
Avatar of HainKurt
HainKurt
Flag of Canada image

why you dont use sessions?

normally, you add hidden vars into forms

<form ...>
<input type="hidden" name="userid" value="<%=Session("UserID")%>">
</form>

Open in new window


then on target page

UserID = Request("UserID")

Open in new window

Avatar of Michael Sterling

ASKER

@HainKurt: Website is on a server farm. How do I assign to those hidden vars in C#?
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm hosting the site on GoDaddy. I'm using a my sequel database.
I tried using session variables on the server farm, and they would never maintain their values in between pages.
what product are you using, please send me GoDaddy farm product...
you should set them to use same session...
maybe add a sql server to the farm or use same web config...
or use sticky sessions somehow...

the other solution is really pain!
I mean write web app without session :)
Understood, but I did not create or design GoDaddy webfarm. I am stuck in this situation, and not able to use session-variables at all. Albeit a pain, I really need to know how to post a response to a page, and retrieve it using a GET. Do you have any examples of that?
I gave you how to do that in my first post...

you can post to a page, but you cannot get it if page re-send it back :)

you can use cookies, but it is not secure...

can I get the link to GoDaddy farm product...
Sure you want the link to my website? On GoDaddy?
How do I assign a value to the hidden Field, in C#?
godaddy farm product... I did not see it here

https://ca.godaddy.com/hosting/windows-hosting#compare
aspx
<asp:HiddenField id="userid" value="" />

Open in new window


c#
userid.value="HainKurt";

Open in new window


js
alert(document.getElementById("<%=userid.ClientId%>").value);

Open in new window


jQuery
alert($("#<%=userid.ClientId%>").val());

Open in new window

Ok. i don't need to use runat="server"?
Avatar of David Johnson, CD
neither did I when I checked their business plans https://ca.godaddy.com/hosting/business-hosting

So what plan do you have?
:) yes of course, I forgot to add runat="server" part
I really I would not go to sessionless hosting solution!
you should somehow enable use sessions...
without sessions, it will be nightmare to build any web site :)
I've called into customer support and have been told that they don't allow session variables in a server farm. when you think about it, it makes sense, because you're not always going to return to the same server.
I've tested the hidden field and I'm still not getting any value / empty string. In my default.aspx page (my login page) I set my hidden field value as such:

                    HiddenField hf = (HiddenField)this.Master.FindControl("hdfldTest");
                    hf.Value = dbr["UserStatus"].ToString();

Open in new window


Then when I go to the landing page, after the login, I check for the value like this and get nothing:

HiddenField hf = (HiddenField)this.Master.FindControl("hdfldTest");
string temp = hf.Value.ToString();

Open in new window

when you think about it, it makes sense, because you're not always going to return to the same server.

but, in farm, there is a load balancer which allocates sessions to servers...
it can be adjusted to use sticky session, ie, same guy always hit on same server...

what product did you get? I never saw godady/farm hosting :)
I need to see whats going om...
if you create a test login and provide url then I can check...
I got one of the hosting packages on their "Plesk" hosting platform. I don't have access to the load balancer to set it to use sticky sessions. Also, changing that setting for me would change it for all of their users. I don't think they're going to do that.
HainKurt, check your inbox
ok, what should I do here to reproduce the issue?
the error is behind the scenes. i guess this way wont work.
I see lots of errors left and right...

http://test.sjushtracker.com/Reports.aspx?UserStatus=ADMIN
Line 199:				oMail.Body = TESTING PHASE + <br/> + ltReport.Text;

Open in new window


should be
oMail.Body = "TESTING PHASE<br/>" + ltReport.Text;

Open in new window


http://test.sjushtracker.com/LoadStudents.aspx?UserStatus=ADMIN
Line 205:                cmd = Utility.AddNewStudentRecord;

Open in new window

Compiler Error Message: CS0117: 'Utility' does not contain a definition for 'AddNewStudentRecord'
???
Ok. i'm working on those issues but they don't affect the fact that my hidden variables are not passing between pages.
on which page do you have hidden vars?
My master page is where they were. I don't have them now.
thanks for your help and patience