How to send Request.Form

Go To


I'm doing something really bad with my code. I'm getting all data posted to the actual page and putting into html inputs:

private void GetPostedForm()
    System.Text.StringBuilder displayValues = new System.Text.StringBuilder();
    System.Collections.Specialized.NameValueCollection postedValues = Request.Form;

    for (int i = 0; i < postedValues.AllKeys.Length; i++)
        String nextKey = postedValues.AllKeys[i];
        if (nextKey.Substring( 0, 2 ) != "__")
            displayValues.Append( "<input type='hidden' name='" + nextKey + "' value='" + postedValues[i] + "'/>" );
    hiddensPost.InnerHtml = displayValues.ToString();

But the html inputs in this page are useless to me. I'm putting a page between 2 older pages ("A" sent form to "B"). Now I need to send "A" to "X" and then send to "B".

The question is: How can I put the requested form into the actual form to send to the next page without doing all this mess in HTML?

2012-04-03 19:52
by Thiago
From the moment you do all that, I am sure that you know to do that by your self, and I am not understand why the question - where did you have stack. And the render to simple input html is not bad from the moment that you only pass the values from the one to the other. The only think here is where you render them, and you have forget to HtmlEncode the value of the - Aristos 2012-04-03 20:34
I only type it as StringBuilder displayValues = new StringBuilder();

for (int i = 0; i < HttpContext.Current.Request.Form.Count; i++) { if (HttpContext.Current.Request.Form.Keys[i].Substring( 0, 2 ) != "__") { displayValues.AppendFormat("" HttpContext.Current.Request.Form.Keys[i],
HttpContext.Current.Server.HtmlEncode(HttpContext.Current.Request.Form[i].ToString()) ); } }

// on a litera I will place that. txtOnMe.Text = displayValues.ToString() - Aristos 2012-04-03 20:39


You can put your steps(A,X,B) and it's visible inputs, into separate asp-panels(pnlA,pnlX,pnlB)

then simply toggle panels visibility in which state you want.the ViewState will do it for you (store controls states into one hidden field within the form to post again with inputs)

so you may post user entered data 3 times with one html form( the famous form)

another solution is here , the wizard control

2012-04-03 20:13
by pylover


If you can, just change the method to GET and pass the QueryString along from page to page.

2012-04-03 20:24
by James Johnson