HowTo: get request.form[i].name

Discussion in 'ASP .Net' started by Wilhelm Pieper, Jul 6, 2003.

  1. Hello,

    HowTo: catch name/value pairs from request.form?

    My viewstate shows:
    "__VIEWSTATE=..&111=5.."
    I want to get this pairs of IDs/names [111] and values [5].
    But because the DropDownList ist dynamically created I don't know the
    name/ID of the created list. I can parse the viewState string to get the
    related name/value pairs, but I think there will be a more simple way
    provided by the request-object??

    wkr: Wilhelm Pieper
     
    Wilhelm Pieper, Jul 6, 2003
    #1
    1. Advertising

  2. Wilhelm Pieper

    Natty Gur Guest

    Hi,

    I don’t know how you get the data from __viewstate field. This data is
    handling by the LosFormatter class. This class serializes the values of
    the controls into string presentation. The data format in the
    __viewstate isn’t in key=value format.

    Anyway you can get data from the Form Collection:
    string x = Request.form["myTextControl"];

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, Jul 6, 2003
    #2
    1. Advertising

  3. "Natty Gur" <> schrieb im Newsbeitrag
    news:...


    > I don't know how you get the data from __viewstate field. ..

    Debugger :)
    >
    > Anyway you can get data from the Form Collection:
    > string x = Request.form["myTextControl"];

    But I don't know the name "myTextControl".
    When getting the request.forms string I loop through this string and get
    the values I'm looking for but not the names related to this items:
    for (int i=0;i<Request.Form.Count;i++)

    Double dTmp = Convert.ToDouble(Request.Form.ToString());


    if (dTmp > 0) ..
     
    Wilhelm Pieper, Jul 6, 2003
    #3
  4. Wilhelm Pieper

    Natty Gur Guest

    OK,

    1)using debugger nice :).

    2)What you really after? viewstate will return the last state of the
    control on the server while Form collection holds the values that sends
    from the client.

    Any way if you want you can:
    1) Use the LosFormatter class to get the cached data from the
    __viewstate field.
    2) Loop through the form elements (as you already did) to get the data
    Send from the client
    3) Loop through the WebForm controls to get their current values (the
    cached data and the one that changed by the user).

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, Jul 6, 2003
    #4
  5. Hello Natty,

    thanks to your reply.
    Because your solution looks a little bit more code I tried
    string[] strRequest = Request.Form.ToString().Split('&');

    This returns all pairs I'm interested in in an easy to parse array like:
    "112=5", "113=4" and so on.


    "Natty Gur" <> schrieb im Newsbeitrag
    news:#...
    ...
    > 1) Use the LosFormatter class to get the cached data from the
    > __viewstate field.

    Isn't this the same like Request.Form.ToString()??

    > 2) Loop through the form elements (as you already did) to get the data
    > Send from the client
    > 3) Loop through the WebForm controls to get their current values (the
    > cached data and the one that changed by the user).

    I could (probably) do, but I'm not shure with this because my controls are
    added on the fly.
    So they may be not part of the controls collection.

    wkr: Wilhelm Pieper
     
    Wilhelm Pieper, Jul 6, 2003
    #5
  6. Wilhelm Pieper

    David Waz... Guest

    I think you have a fundimental misunderstanding of .Net

    you DON"T need access to viewstate. The value of your control is
    automatically restored in your application on post-back. You query it's
    value then.

    These three properties should give you what you want

    "DropDownControl.SelectedValue"
    "DropDownControl.SelectedIndex"
    "DropDownControl.SelectedItem"

    ..Net removes you from dealing with the behind the scene plumbing of the
    web - GONE are the days of splitting on "&" etc etc etc.
    (unless you are a PHP pup (doh!))


    "Wilhelm Pieper" <> wrote in message
    news:eze#$...
    > Hello,
    >
    > HowTo: catch name/value pairs from request.form?
    >
    > My viewstate shows:
    > "__VIEWSTATE=..&111=5.."
    > I want to get this pairs of IDs/names [111] and values [5].
    > But because the DropDownList ist dynamically created I don't know the
    > name/ID of the created list. I can parse the viewState string to get the
    > related name/value pairs, but I think there will be a more simple way
    > provided by the request-object??
    >
    > wkr: Wilhelm Pieper
    >
    >
     
    David Waz..., Jul 6, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian H
    Replies:
    1
    Views:
    887
    Natty Gur
    Jul 29, 2003
  2. John Davis
    Replies:
    2
    Views:
    399
    Dave Anderson
    Aug 18, 2003
  3. Java  script  Dude

    IE name="name" & form.name property bug

    Java script Dude, Jun 29, 2004, in forum: Javascript
    Replies:
    5
    Views:
    252
    Java script Dude
    Jun 30, 2004
  4. Pavils Jurjans
    Replies:
    3
    Views:
    194
    Pavils Jurjans
    Mar 18, 2005
  5. Replies:
    6
    Views:
    179
Loading...

Share This Page