ASP.Net/Development/Form Self Submit

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Form submit value to the save page without action url

<%@ Page Language="VB" %>
<script runat="server">
    Sub Page_Load(Sender As Object, E As EventArgs)
        If Request.Form("txtName") <> "" Then
            lblSentence.Text = Request.Form("txtName") _
                & " selected " & Request.Form("ddlColor")
        End If
    End Sub
</script>
<html>
<head>
<title>ASP.NET Viewstate Form Sample #1</title>
</head>
<body bgcolor="#FFFFFF">
<form method="post">
    Enter Your Name:
    <input type="text" id="txtName" name="txtName" />
    Pick a Color:
    <select id="ddlColor" name="ddlColor">
        <option>Red</option>
        <option>Orange</option>
        <option>Yellow</option>
        <option>Green</option>
        <option>Blue</option>
        <option>Indigo</option>
        <option>Violet</option>
    </select>
    <input type="submit" id="btnSubmit" text="Submit" />
</form>
<asp:label id="lblSentence" runat="server" />
</body>
</html>



Submitting and displaying form values in ASP.NET

<%@ Page Language="vb" %>
<html>
   <head>
      <title>Submitting and displaying form values in ASP.NET</title>
   <script runat="server">
      Sub Page_Load()
         If Request.HttpMethod = "POST" Then
            Dim Counter1 As Integer
            Dim Keys() As String
            Dim FormElements As NameValueCollection
            FormElements=Request.Form
            Keys = FormElements.AllKeys
            For Counter1 = 0 To Keys.GetUpperBound(0)
               Response.Write("Form " & Counter1 & " name: " & Keys(Counter1) & "<br>")
               Response.Write("Form " & Counter1 & " value: " & FormElements(Counter1) & "<br>")
            Next Counter1
         End If 
      End Sub
   </script>
   </head>
<body>

<%
If Request.HttpMethod = "GET" Then
%>
<form id="Form1" method="post">
   First Name: 
   <br>
   <input type="text" id="txtFName" name="txtFName">
   <br>
   Last Name: 
   <br>
   <input type="text" id="txtLName" name="txtLName">
   <br>
   <input type="submit" value="Submit" id="Submit1">
</form>
<%
End If
%>
</body>
</html>