Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

POST parameters in ASP.NET

Posted on 2011-09-18
9
Medium Priority
?
335 Views
Last Modified: 2012-05-12
I want to redirect to another ASP.NET (C#) page and at the same time, pass POST parameters to it.
On the second page, I want to retrieve these parameters.

If possible, please provide some sample code. Thanks!
0
Comment
Question by:dshrenik
9 Comments
 
LVL 14

Expert Comment

by:nishant joshi
ID: 36557094
0
 

Author Comment

by:dshrenik
ID: 36557098
The link is broken.
0
 
LVL 14

Accepted Solution

by:
nishant joshi earned 500 total points
ID: 36557100
http://w3schools.com/aspnet/aspnet_forms.asp


there is a problem with link tag in EE.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dshrenik
ID: 36557111
I want to do it this way:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

I am not sure how I can POST parameters, and also redirect to the url. The webpage represented by "url" must then retrieve the POST parameters.
0
 
LVL 14

Expert Comment

by:nishant joshi
ID: 36557129
0
 
LVL 3

Assisted Solution

by:ExpertLogin_890
ExpertLogin_890 earned 500 total points
ID: 36559198
you can pass the post parameter by using the form collection with Request object add the hidden fields for parameter those you want to pass through the pages those you dont want to view by others
your form having fields like

ID: <input name="ID">
 Name : <input name="name">
Addres:  <input name="address">

etc.
and submit the form using form.submit method using post method
you can retrieves the values in code behing page

Request.Form("firstname")

or in htmlcode file

<%=Request.Form%>  





0
 
LVL 7

Assisted Solution

by:gopaltayde
gopaltayde earned 500 total points
ID: 36560046
here is the link for cross page postback

http://msdn.microsoft.com/en-us/library/ms178139.aspx
0
 
LVL 19

Assisted Solution

by:Manoj Patil
Manoj Patil earned 500 total points
ID: 36560130
you can try with following code

void Page_Load(object sender, EventArgs e)
{
    System.Text.StringBuilder displayValues = 
        new System.Text.StringBuilder();
    System.Collections.Specialized.NameValueCollection 
        postedValues = Request.Form;
    String nextKey;
    for(int i = 0; i < postedValues.AllKeys.Length; i++)
    {
        nextKey = postedValues.AllKeys[i];
        if(nextKey.Substring(0, 2) != "__")
        {
            displayValues.Append("<br>");
            displayValues.Append(nextKey);
            displayValues.Append(" = ");
            displayValues.Append(postedValues[i]);
        }
    }
   Label1.Text = displayValues.ToString();
}

Open in new window


For more ways check following link
http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx#Y2052
0
 

Author Comment

by:dshrenik
ID: 36564070
The problem is that I need to construct the POST parameters with C# code. They're not values of form elements.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question