Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay Jon, the viewstate issue first:</p> <p>I haven't checked if there's any kind of internal code change since 2.0 but here's how I handled getting rid of the viewstate a few years ago. Actually that hidden field is hardcoded inside HtmlForm so you should derive your new one and step into its rendering making the calls by yourself. Note that you can also leave __eventtarget and __eventtarget out if you stick to plain old input controls (which I guess you'd want to since it also helps not requiring JS on the client):</p> <pre><code>protected override void RenderChildren(System.Web.UI.HtmlTextWriter writer) { System.Web.UI.Page page = this.Page; if (page != null) { onFormRender.Invoke(page, null); writer.Write("&lt;div&gt;&lt;input type=\"hidden\" name=\"__eventtarget\" id=\"__eventtarget\" value=\"\" /&gt;&lt;input type=\"hidden\" name=\"__eventargument\" id=\"__eventargument\" value=\"\" /&gt;&lt;/div&gt;"); } ICollection controls = (this.Controls as ICollection); renderChildrenInternal.Invoke(this, new object[] {writer, controls}); if (page != null) onFormPostRender.Invoke(page, null); } </code></pre> <p>So you get those 3 static MethodInfo's and call them out skipping that viewstate part out ;)</p> <pre><code>static MethodInfo onFormRender; static MethodInfo renderChildrenInternal; static MethodInfo onFormPostRender; </code></pre> <p>and here's your form's type constructor:</p> <pre><code>static Form() { Type aspNetPageType = typeof(System.Web.UI.Page); onFormRender = aspNetPageType.GetMethod("OnFormRender", BindingFlags.Instance | BindingFlags.NonPublic); renderChildrenInternal = typeof(System.Web.UI.Control).GetMethod("RenderChildrenInternal", BindingFlags.Instance | BindingFlags.NonPublic); onFormPostRender = aspNetPageType.GetMethod("OnFormPostRender", BindingFlags.Instance | BindingFlags.NonPublic); } </code></pre> <p>If I'm getting your question right, you also want not to use POST as the action of your forms so here's how you'd do that:</p> <pre><code>protected override void RenderAttributes(System.Web.UI.HtmlTextWriter writer) { writer.WriteAttribute("method", "get"); base.Attributes.Remove("method"); // the rest of it... } </code></pre> <p>I guess this is pretty much it. Let me know how it goes.</p> <p>EDIT: I forgot the Page viewstate methods:</p> <p>So your custom Form : HtmlForm gets its brand new abstract (or not) Page : System.Web.UI.Page :P</p> <pre><code>protected override sealed object SaveViewState() { return null; } protected override sealed void SavePageStateToPersistenceMedium(object state) { } protected override sealed void LoadViewState(object savedState) { } protected override sealed object LoadPageStateFromPersistenceMedium() { return null; } </code></pre> <p>In this case I seal the methods 'cause you can't seal the Page (even if it isn't abstract Scott Guthrie will wrap it into yet another one :P) but you can seal your Form.</p>
    singulars
    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.
 

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