Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This solution will give you programmatic access to the controls in their entirety including all attributes on the controls. Also, only the text box values will appear in the URL upon submission so your GET request URL will be more "meaningful"</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JonSkeetForm.aspx.cs" Inherits="JonSkeetForm" %&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 runat="server"&gt; &lt;title&gt;Jon Skeet's Form Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="JonSkeetForm.aspx" method="get"&gt; &lt;div&gt; &lt;input type="text" ID="text1" runat="server" /&gt; &lt;input type="text" ID="text2" runat="server" /&gt; &lt;button type="submit"&gt;Submit&lt;/button&gt; &lt;asp:Repeater ID="Repeater1" runat="server"&gt; &lt;ItemTemplate&gt; &lt;div&gt;Some text&lt;/div&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Then in your code-behind you can do everything you need on PageLoad</p> <pre><code>public partial class JonSkeetForm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { text1.Value = Request.QueryString[text1.ClientID]; text2.Value = Request.QueryString[text2.ClientID]; } } </code></pre> <p>If you don't want a form that has <code>runat="server"</code>, then you should use HTML controls. It's easier to work with for your purposes. Just use regular HTML tags and put <code>runat="server"</code> and give them an ID. Then you can access them programmatically <strong>and</strong> code without a <code>ViewState</code>. </p> <p>The only downside is that you won't have access to many of the "helpful" ASP.NET server controls like <code>GridView</code>s. I included a <code>Repeater</code> in my example because I'm assuming that you want to have the fields on the same page as the results and (to my knowledge) a <code>Repeater</code> is the only DataBound control that will run without a <code>runat="server"</code> attribute in the Form tag.</p>
 

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