Note: More comprehensive instances of the element class will be supplemented later.
Front-end:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> mootools [1] -- advanced application example of element </title>
<SCRIPT type = "text/JavaScript" Language = "JavaScript" src = "mootools-1.2-core-jm.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
// Add an operation event to the page-domready.
Window. addevent ("domready", function (){
// Add a click event for btnsent.
$ ('Btnsent'). addevent ('click', function (){
If ($ ('txtcontent'). innertext = ''){
Alert ('the sent content cannot be blank! ');
Return;
}
// Ult2.aspx creates a page. In fact, it stores data temporarily and extracts and displays the data in MessageBox.
VaR url = 'default2. aspx ';
VaR postdata = $ ("postmessage"). toquerystring ();
New Ajax (URL, {method: 'post', oncomplete: function (){
$ ('Messagebox'). innerhtml + = This. response. text;
// The innerhtml method can be replaced by sethtml, because innerhtml is used in Dom operations, and sethtml is newly defined in the mootools framework.
}
}). Request (postdata );
});
});
</SCRIPT>
</Head>
<Body>
<Div style = "margin: auto; text-align: center;">
<Div style = "width: pixel PX; Height: 700px;">
<Div id = "MessageBox"> </div>
<HR/>
<Form ID = "postmessage" method = "Post" name = "postmessage" runat = "server">
<Div>
<Ul>
<Li style = "list-style-type: none;"> enter your network name: & nbsp; <input id = "txtname" runat = "server" value = "Enter the network name"/>
</LI>
</Ul>
<Ul>
<Li style = "list-style-type: none;"> enter the content to be sent: <textarea id = "txtcontent" runat = "server" Cols = "20" rows = "4"> </textarea> </LI>
</Ul>
<Ul>
<Li style = "list-style-type: none; "> <input type =" button "id =" btnsent "runat =" server "value =" send "onserverclick =" btnsent_serverclick "/> </LI>
</Ul>
</Div>
</Form>
</Div>
</Div>
</Body>
</Html>
Background:
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class _ default: system. web. UI. page
{< br> protected void page_load (Object sender, eventargs e)
{< br> If (ispostback)
{< br> If (! String. isnullorempty (txtname. Value )&&! String. isnullorempty (txtcontent. value. Trim ()
{
String name = txtname. value. Trim ();
String content = txtcontent. value. Trim ();
String MSG = "<div> <ul> <li>" + name + ":" + content + "</LI> </ul> </div> ";
Response. Clear ();
Response. Write (MSG );
Response. End ();
}
Else if (! String. isnullorempty (txtcontent. value. Trim () & string. isnullorempty (txtname. Value ))
{
String name = "Tourist ";
String content = txtcontent. value. Trim ();
String MSG = "<div> <ul> <li>" + name + ":" + content + "</LI> </ul> </div> ";
Response. Clear ();
Response. Write (MSG );
Response. End ();
}
}
}
}