ASP.NET WebForms has pros and cons. We like its server side event model. We don't like its messy client side Id and view state.

Rabbit Framework introduces a new web form engine, which uses HTML 5 data attributes and unobtrusive JavaScript. It has clean Ids. No view state. And It supports multiple forms on a page.
  • Attribute data-runat="server" triggers default server side event {element id}_click() upon element's onclick event.
  • Attribute data-runat="server-auto" triggers default server side event {element id}_click() upon element's onchange event.
  • Attribute data-server-event="button_click" defines server side event name.
  • Attribute data-server-event-arg="foo" passes parameter to server side event.
  • Post back can be triggered in JavaScript using webForm.postback(element), where the element's closest form will be posted.

<form method="post" action="">
    Enter something: <input type="text" name="name" value="@name"/><br /><br />
    <button id="button" value="test" data-runat="server">Run Default Event</button>
<div id="msg">@name</div>

On the server side, the event handler has meaningful parameters. No more meaningless/useless sender and argument pattern that is used everywhere in ASP.NET WebForms. Rabbit Framework Web Forms engine will feed the parameters with data comes in the HTML form posted.

@using Rabbit
@inherits WebForm

@functions {
    public string name = ""; // value will be pushed to JavaScript as 
    void button_click(string username) // value will be set from <input type="text" name="username"/>
        // ......

See the demo page Demo_WebForm.cshtml from the sample site.

Last edited Jul 23, 2011 at 8:46 PM by yysun, version 4


No comments yet.