Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're definitely (IMHO) on the right track by not using runat="server" in your FORM tag. This just means you'll need to extract values from the Request.QueryString directly, though, as in this example:</p> <p>In the .aspx page itself:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="FormPage.aspx.cs" Inherits="FormPage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;ASP.NET with GET requests and no viewstate&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;asp:Panel ID="ResultsPanel" runat="server"&gt; &lt;h1&gt;Results:&lt;/h1&gt; &lt;asp:Literal ID="ResultLiteral" runat="server" /&gt; &lt;hr /&gt; &lt;/asp:Panel&gt; &lt;h1&gt;Parameters&lt;/h1&gt; &lt;form action="FormPage.aspx" method="get"&gt; &lt;label for="parameter1TextBox"&gt; Parameter 1:&lt;/label&gt; &lt;input type="text" name="param1" id="param1TextBox" value='&lt;asp:Literal id="Param1ValueLiteral" runat="server" /&gt;'/&gt; &lt;label for="parameter1TextBox"&gt; Parameter 2:&lt;/label&gt; &lt;input type="text" name="param2" id="param2TextBox" value='&lt;asp:Literal id="Param2ValueLiteral" runat="server" /&gt;'/&gt; &lt;input type="submit" name="verb" value="Submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and in the code-behind:</p> <pre><code>using System; public partial class FormPage : System.Web.UI.Page { private string param1; private string param2; protected void Page_Load(object sender, EventArgs e) { param1 = Request.QueryString["param1"]; param2 = Request.QueryString["param2"]; string result = GetResult(param1, param2); ResultsPanel.Visible = (!String.IsNullOrEmpty(result)); Param1ValueLiteral.Text = Server.HtmlEncode(param1); Param2ValueLiteral.Text = Server.HtmlEncode(param2); ResultLiteral.Text = Server.HtmlEncode(result); } // Do something with parameters and return some result. private string GetResult(string param1, string param2) { if (String.IsNullOrEmpty(param1) &amp;&amp; String.IsNullOrEmpty(param2)) return(String.Empty); return (String.Format("You supplied {0} and {1}", param1, param2)); } } </code></pre> <p>The trick here is that we're using ASP.NET Literals inside the value="" attributes of the text inputs, so the text-boxes themselves don't have to runat="server". The results are then wrapped inside an ASP:Panel, and the Visible property set on page load depending whether you want to display any results or not.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload