Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    text grab and outout in asp pages

    I am building a website in asp.net and want to know how to take text from a text box on say the home page and output that text in a text box on another page. can anybody help please?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Several options. Depends on your goal.
    -- Cross page post back
    -- contaxt state bag
    -- Session state bag
    -- Application state bag
    -- cookie

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the text thats dispalyed back out in a different text box on a different page is just used to reference a user in the database. what do you suggest is the best option to just take it from one text box on one page and dipslay it in another text box on another page?

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Are the two pages connected by a link or by a form submit? Or are they merely two pages on the site, with no particular connection?
    Confirm this is .NET and not classic asp too please.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes sorry it is .net and the pages are connected by a Response.Redirect. how it works is if the login is succesfull, the username is copied from the username text box on the sign in form to a text box on the user menu.

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Ah, if it's the username, you may want it in more places later. You can go ahead and store something like that in the Session.
    You may want to check out Server.Transfer instead of Response.Redirect as well. You keep all your header info with Transfer and it doesn't ding the browser. Response.Redirect actually sends a 302 Redirect to the browser (which tends to lose cookie info and whatnot and sometimes even the session data if it is set to use cookies instead of the URL).
    Transfer stays on the server and you keep cookies and other header data.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for your help so far i appreciate it very much, but i am not a very experienced programmer and was wondering if you could give me the basic building blocks for the session transfer as i do not know where to start, thanks again

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Does this help?
    It's from my application, actually. I use context state bag here, which might work for you, too. It's like Session, but only works over the Request, so Transfer does pass it.
    (C#)

    Code:
            if (userParams.Count == 0) Context.Items["UserParams"] = null;
            else Context.Items["UserParams"] = userParams;
            Context.Items["Report"] = report;
            ViewState["Report"] = report;
            
            Server.Transfer("ReportRunReport.aspx?report_id=" + report.ReportID);

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    Regular Coder Freon22's Avatar
    Join Date
    May 2005
    Location
    USA
    Posts
    287
    Thanks
    3
    Thanked 5 Times in 5 Posts
    There are alot of ways to move data across pages. If you are using a low cost hosting company then I would not use sessions. The reason for this is they use web farms. What happens is as a server get loaded up they will move some of the load to other servers. When they move you not if, you will lose all sessions on that server. Most of these hosting companies will even warn you to not use sessions for this reason.

    There are querystrings but the problem with querystrings is the user can see what is in the string and can mess with it. Cookies gives you a little more control but there again with the help of free broswer plugins the user can see and play with the cookies.

    When I was with the low cost hosting companies I would uses a combination of sessions, cookies, and database. To tell who was who and what they can or can not do. I used the cookies to refresh my sessions if the web farms has droped the session. I would use the session to make sure they were not messing with the cookie. So anyway you can see that keeping state with the server can be a pain.

    If all you want to do is move a small amount of text from a textbox on one page to a textbox on another page. You can use a form using the post method or a cookie.

    Find yourself a good book or online tutorial. Here are some links to get you started. The first link will show you how the write and call cookies, the next link is a good online free tutorial.
    http://msdn2.microsoft.com/en-us/library/ms178194.aspx
    http://www.w3schools.com/aspnet/


    Hope this helps.

  • #10
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the advice. just to say, my project is only for a degree project and it will not be going live where a number of users will be using it. it is merely for a project presentation where i have to show the program working. thanks for the help, i`l try the tutorilas out now

  • #11
    New Coder
    Join Date
    Jan 2007
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, i follwed the tutoril and it worked perfectly using the code :

    to write a cookie:

    Response.Cookies("userName").Value = "" + txtUsername.text
    Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)

    Dim aCookie As New HttpCookie("lastVisit")
    aCookie.Value = DateTime.Now.ToString()
    aCookie.Expires = DateTime.Now.AddDays(1)
    Response.Cookies.Add(aCookie)

    and to read the cookie:

    If Not Request.Cookies("userName") Is Nothing Then
    Label1.Text = Server.HtmlEncode(Request.Cookies("userName").Value)
    End If

    If Not Request.Cookies("userName") Is Nothing Then
    Dim aCookie As HttpCookie = Request.Cookies("userName")
    Label1.Text = Server.HtmlEncode(aCookie.Value)
    End If

    thanks for all the help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •