Export (0) Print
Expand All

HtmlForm.Enctype Property

Gets or sets the encoding type a browser uses when posting the form's data to the server.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

public string Enctype { get; set; }
/** @property */
public String get_Enctype ()

/** @property */
public void set_Enctype (String value)

public function get Enctype () : String

public function set Enctype (value : String)

Property Value

A string that contains the encoding type. The default value is an empty string (""), indicating that the browser's default content type is used.

Use the Enctype property to specify the encoding type a browser uses to post data back to the server.

The following table shows the common encoding types.

Encoding type

Description

application/x-www-form-urlencoded

Form data is encoded as name/value pairs. This is the standard encoding format.

multipart/form-data

Form data is encoded as a message with a separate part for each control on the page.

text/plain

Form data is encoded in plain text, without any control or formatting characters.

For more information on encoding types, see the World Wide Web Consortium (W3C Web site.

The following code example demonstrates how to use the Enctype property to specify the encoding type the browser uses to send data back to the server.


<%@ Page Language="C#" AutoEventWireup="True" %>

<script runat="server">

  protected void AddButton_Click(Object sender, EventArgs e)
  {

    int Answer;

    // Calculate and display the result.
    Answer = Convert.ToInt32(Value1.Value) + Convert.ToInt32(Value2.Value);
    AnswerMessage.InnerHtml = Answer.ToString();

  }
     
</script>
<html> 

<head>

  <title>HtmlForm Example</title>

</head>

<body>

   <form Method="Post"
         Enctype="application/x-www-form-urlencoded" 
         runat="server" id="myform">

      <h3> HtmlForm Example </h3>

      <table>

         <tr>

            <td colspan="5">

               Enter integer values into the text boxes. <br>
               Click the Add button to add the two values. <br>
               Click the Reset button to reset the text boxes.

            </td>

         </tr>

         <tr>

            <td colspan="5">

               &nbsp;

            </td>

         </tr>

         <tr align="center">

            <td>

               <input ID="Value1"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>

            </td>

            <td>

               + 

            </td>

            <td>

               <input ID="Value2"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>

            </td>

            <td>

               =

            </td>

            <td>
               
               <span ID="AnswerMessage"
                     runat="server"/>

            </td>

         </tr>

         <tr>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value1RequiredValidator"
                    ControlToValidate="Value1"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value1MinCompareValidator"
                    ControlToValidate="Value1"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value1MaxCompareValidator"
                    ControlToValidate="Value1"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value2RequiredValidator"
                    ControlToValidate="Value2"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value2MinCompareValidator"
                    ControlToValidate="Value2"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value2MaxCompareValidator"
                    ControlToValidate="Value2"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td>

               &nbsp
 
            </td>

         </tr>

         <tr align="center">

            <td colspan="4">

               <input Type="Submit"
                      Name="AddButton"
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>

               &nbsp;&nbsp;&nbsp;

               <input Type="Reset"
                      Name="AddButton"
                      Value="Reset"
                      runat="server"/>

            </td>

            <td>

               &nbsp;

            </td>

         </tr>

      </table>

   </form>

</body>
</html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft