Handling Post Request

  • Thread starter Thread starter Samuel Shulman
  • Start date Start date
S

Samuel Shulman

I have to create a page that all it does it handle a 'POST' request with
some parameters

So I created a blank page and in the Load event I try to handle the
parameters passed but the page doesn't open it and returns some error

Any suggestions?

Samuel
 
What error does it return? It's really hard to know what is going on without
knowing the error.

To handle post items, you would access them through the Request.Form
collection. What you'll need to do though is always test to ensure that the
form collection item is not null before you access it. If it's null you'll
get an error. In C# it would look like this.

string myVariable = string.Empty;

if(Request.Form["myvariable"] != null)
{
myVariable = Request.Form["myvariable"].ToString();
}

Keep in mind that all items are strings that are passed in since they are
all text. If it's another type, such as integer, you'll have to convert it
yourself. An example of an integer is (of course, still check to see if the
form field is null first):

int myVariable = Convert.ToInt32(Request.Form["myvariable"].ToString());
 
it was a security problem
thank you,
samuel

Mark Fitzpatrick said:
What error does it return? It's really hard to know what is going on
without knowing the error.

To handle post items, you would access them through the Request.Form
collection. What you'll need to do though is always test to ensure that
the form collection item is not null before you access it. If it's null
you'll get an error. In C# it would look like this.

string myVariable = string.Empty;

if(Request.Form["myvariable"] != null)
{
myVariable = Request.Form["myvariable"].ToString();
}

Keep in mind that all items are strings that are passed in since they are
all text. If it's another type, such as integer, you'll have to convert it
yourself. An example of an integer is (of course, still check to see if
the form field is null first):

int myVariable = Convert.ToInt32(Request.Form["myvariable"].ToString());


--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

Samuel Shulman said:
I have to create a page that all it does it handle a 'POST' request with
some parameters

So I created a blank page and in the Load event I try to handle the
parameters passed but the page doesn't open it and returns some error

Any suggestions?

Samuel
 
Back
Top