How to POST a FORM from HTML to ASPX page

前端 未结 8 1633
你的背包
你的背包 2020-11-30 03:36

How do I post a form from an HTML page to and ASPX page (2.0) and be able to read the values?

I currently have an ASP.NET site using the Membership provider and ever

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 03:58

    In the html form, you need to supply additional viewstate variable and disable ViewState in a server page. This requires some control on both sides , though.

    Form HTML:

     

    Note empty __VIEWSTATE.

    WebForm.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="WebForm.aspx.cs" Inherits="WebForm"
     EnableEventValidation="False" EnableViewState="false" %>
    
    
    
    
    
        
    
    
        

    Note EnableEventValidation="False", EnableViewState="false" to prevent validation error for empty view state. Code Behind/Inherits values are not precise.

    WebForm.cs:

    public partial class WebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string value = Encoding.Unicode.GetString(Convert.FromBase64String(this.postData.Text));
        }
    }
    

提交回复
热议问题