Results 1 to 8 of 8

Thread: Getting Posted Variables

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Getting Posted Variables

    Hi, I have a weform that gets data from the user... i then Post the data to the next page which processes it and enters it into the database.

    How do i get the values of the variables that were posted to the next page?


    In PHP you simply put

    $Title = $_POST[txtTitle]

    In ASP i have no clue

    Thanks!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I am not sure how to get posted variables, but I use Request.QueryString for query string values. Maybe what you are looking for is in the Request object.

  3. #3

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    What do you mean by query string values?

    I just want to get the values of the textboxes on the last page that were posted to the next page.


    For example i have a form tag
    VB Code:
    1. <form name="form" action="addnews2.aspx" method="post">
    2.  
    3. 'and inside that form i have 2 text fields
    4.  
    5. <input id="txtTitle" type="text" maxLength="75" size="50" name="txtTitle" runat="server">
    6.  
    7. <input id="txtNews" type="text" maxLength="75" size="50" name="txtTitle" runat="server">
    8.  
    9. 'then i have a submit button
    10.  
    11. <input onmousedown="Validate()" type="submit" value="Add News" name="Submit">
    12.  
    13. </form>


    So when someone clicks the Add News button it Posts the info in those text boxes to the server and goes to the next page addnews2.aspx. Now i want to get the values of those textboxes and use them in addnews2.aspx.


    Am i going about thsi the wrong way? That's how it's done in PHP, i assumed that's how it was done in ASP too..
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    http://msdn.microsoft.com/library/de...sformtopic.asp

    You need the HttpRequest.Form method to return a NameValueCollection that contains your data.

  5. #5

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Thanks, I went to the page and tried the code but as usual it doesn't work, msdn code never seems to work.


    VB Code:
    1. Dim loop1 As Integer
    2.         Dim arr1() As String
    3.         Dim coll As NameValueCollection
    4.         ' Load Form variables into NameValueCollection variable.
    5.         coll = Request.Form
    6.  
    7.         ' Get names of all forms into a string array.
    8.         arr1 = coll.AllKeys
    9.         For loop1 = 0 To arr1.GetUpperBound(0)
    10.             Response.Write("Form: " & arr1(loop1) & "<br>")
    11.         Next loop1

    I assume i need to import some class or something becasue it is saying the NameValueCollection type is not defined..

    I also tried using the HttpRequest.Form thing and got basically the same thing.

    Anyone have a working example?

    Thanks!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Request.form("txtTitle") is the same thing as $_POST[txtTitle]
    in PHP.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Ahh cool deal. Works great! Thanks!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    The above code works, you just have to import System.Collections.Specialized

    If you ever have a problem like that again, where it says NameValueCollection isn't defined, just do a search on the object in the msdn library, you will find its object tree to refer to what to import.

Posting Permissions

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



Click Here to Expand Forum to Full Width