How to know if a page receives a post

2

On a page .aspx ( detail_page.aspx ) I have a code like this, now lower add an HTML form with action to the same page.

How can I know if the page is receiving the post or NOT?

The goal is if you receive the post execute a code and if you do not receive it execute this code that I already have:

<%
         int restaurantId = 0;
         if (!IsPostBack)
         {
             if(Session["idrestaurant"]!= null)
             {
                 int.TryParse(Session["idrestaurant"].ToString(), out restaurantId);
             }
             hfRestaurantId.Value = restaurantId.ToString();//Set restaurantId 
         }

         SaborWebApp.restaurant rest = new SaborWebApp.SaborEntities().restaurant.Where(a => a.RestaurantID == restaurantId).FirstOrDefault();
     %>

Html form

<form method="post" action="../Delivery/detail_page.aspx" name="review" id="review" class="popup-form" /> 

 <input name="name_review" id="name_review" type="text" placeholder="Name" class="form-control form-white" />

<input type="submit" value="Submit" class="btn btn-submit" id="submit-review"/>

</form> 
    
asked by Efrain Mejias C 30.09.2016 в 14:07
source

3 answers

2

Surely you have to use the

Request.HttpMethod

in conjunction with the

HttpRequest.Form

to get the input text data

    
answered by 30.09.2016 / 14:47
source
1

I recommend Postman ; you install it to be able to consume the data and do the tests.

    
answered by 30.09.2016 в 15:29
0

Something like this:

  <%
    var metodo = System.Web.HttpContext.Current.Request.HttpMethod;
    string nameReview, emailReview, textReview;
    decimal foodReview, priceReview, punctualityReview, courtesyReview;
    int verifyReview;
    switch (metodo.ToLower())
    {
        case "post":
            NameValueCollection nameValue = Request.Form;
            if (nameValue.Count > 0)
            {
                nameReview = nameValue["nameReview"].ToString();
                emailReview = nameValue["emailReview "].ToString();
                foodReview = Convert.ToDecimal(nameValue["foodReview"]);
                priceReview = Convert.ToDecimal(nameValue["priceReview"]);
                punctualityReview = Convert.ToDecimal(nameValue["punctualityReview"]);
                courtesyReview = Convert.ToDecimal(nameValue["courtesyReview"]);
                textReview = nameValue["textReview"].ToString();
                verifyReview = Convert.ToInt32(nameValue["verifyReview"]);
                SaborWebApp.Engine.EngineRestaurant Sp = new  SaborWebApp.Engine.EngineRestaurant();
                bool resultadoInsert = Sp.InsertRestaurantReview((int)Session["idRestaurant"], (int)Session["idCliente"], nameReview, textReview, (int) , foodReview, priceReview, punctualityReview, courtesyReview, 0, DateTime.Now, DateTime.Now);

            }
            break;
        case "get":
            if (Request.QueryString.Keys.Count > 0)
            {
                Session["idRestaurant"] = Convert.ToInt32(Request.QueryString["idRestaurant"]);
                Session["idCliente"] = Convert.ToInt32(Request.QueryString["idCliente"]);
                Session["idOrder"] = Convert.ToInt32(Request.QueryString["idOrder"]);
            }
            break;
    }
%>
    
answered by 30.09.2016 в 23:56