ASP.Net/Development/Form Self Submit
Версия от 18:30, 26 мая 2010; (обсуждение)
Form submit value to the save page without action url
<source lang="csharp">
<%@ 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>
</source>
Submitting and displaying form values in ASP.NET
<source lang="csharp">
<%@ 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) & "
") Response.Write("Form " & Counter1 & " value: " & FormElements(Counter1) & "
") Next Counter1 End If End Sub </script> </head>
<body>
<% If Request.HttpMethod = "GET" Then %> <form id="Form1" method="post">
First Name:
<input type="text" id="txtFName" name="txtFName">
Last Name:
<input type="text" id="txtLName" name="txtLName">
<input type="submit" value="Submit" id="Submit1">
</form> <% End If %> </body> </html>
</source>