HtmlTextArea.ServerChange Event
Occurs when the content of the HtmlTextArea control changes between posts to the server.
[Visual Basic] Public Event ServerChange As EventHandler [C#] public event EventHandler ServerChange; [C++] public: __event EventHandler* ServerChange;
[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.
Event Data
The event handler receives an argument of type EventArgs.
Remarks
The ServerChange event is raised when the content of the HtmlTextArea control changes between posts to the server. This event is commonly used to perform data validation on the text box.
Note This event is only raised when the user initiates a post to the server, such as clicking a submit button. This event does not cause a post to the server to occur.
Note The control must have viewstate enabled for the ServerChange event to work correctly.
For more information about handling events, see Consuming Events.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to specify and create a custom event handler for the ServerChange event. A message is displayed when the value entered in the HtmlTextArea control exceeds 10 characters.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Server_Change(sender As Object, e As EventArgs) If TextArea1.Value.Length > 10 Then Span1.InnerHtml = "Your comment cannot exceed 10 characters." Else Span1.InnerHtml = "You wrote: <br>" + TextArea1.Value End If End Sub </script> </head> <body> <form runat=server> <h3>HtmlTextArea Example</h3> Enter your comments: <br> <textarea id="TextArea1" OnServerChange="Server_Change" runat="server"/> <br> <input type="submit" value="Submit" runat="server"/> <p> <span id="Span1" runat="server" /> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Server_Change(Object sender, EventArgs e) { if (TextArea1.Value.Length > 10) Span1.InnerHtml = "Your comment cannot exceed 10 characters."; else Span1.InnerHtml = "You wrote: <br>" + TextArea1.Value; } </script> </head> <body> <form runat=server> <h3>HtmlTextArea Example</h3> Enter your comments: <br> <textarea id="TextArea1" OnServerChange="Server_Change" runat="server"/> <br> <input type="submit" value="Submit" runat="server"/> <p> <span id="Span1" runat="server" /> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script runat="server"> function Server_Change(sender, e : EventArgs) { if (TextArea1.Value.Length > 10) Span1.InnerHtml = "Your comment cannot exceed 10 characters."; else Span1.InnerHtml = "You wrote: <br>" + TextArea1.Value; } </script> </head> <body> <form runat=server> <h3>HtmlTextArea Example</h3> Enter your comments: <br> <textarea id="TextArea1" OnServerChange="Server_Change" runat="server"/> <br> <input type="submit" value="Submit" runat="server"/> <p> <span id="Span1" runat="server" /> </form> </body> </html> [Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Server_Change(sender As Object, e As EventArgs) ' The ServerChange event is commonly used for data validation. ' This method determines whether the comment entered into the ' the HtmlTextArea control is longer than 20 characters. If TextArea1.Value.Length > 20 Then Span1.InnerHtml = "Your comment cannot exceed 20 characters." Else Span1.InnerHtml = "You wrote: <br>" + TextArea1.Value End If End Sub Sub Page_Load(sender As Object, e As EventArgs) ' Create an EventHandler delegate for the method you want to ' handle the event, and then add it to the list of methods ' called when the event is raised. AddHandler TextArea1.ServerChange, AddressOf Server_Change End Sub </script> </head> <body> <form runat=server> <h3>HtmlTextArea ServerChange Example</h3> Enter your comments (20 or fewer characters): <br> <textarea id="TextArea1" runat="server"/> <br> <input type="submit" value="Submit" runat="server"/> <p> <span id="Span1" runat="server" /> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Server_Change(Object sender, EventArgs e) { // The ServerChange event is commonly used for data validation. // This method determines whether the comment entered into the // the HtmlTextArea control is longer than 20 characters. if (TextArea1.Value.Length > 20) { Span1.InnerHtml = "Your comment cannot exceed 20 characters."; } else { Span1.InnerHtml = "You wrote: <br>" + TextArea1.Value; } } void Page_Load(Object sender, EventArgs e) { // Create an EventHandler delegate for the method you want to // handle the event, and then add it to the list of methods // called when the event is raised. TextArea1.ServerChange += new System.EventHandler(this.Server_Change); } </script> </head> <body> <form runat=server> <h3>HtmlTextArea ServerChange Example</h3> Enter your comments (20 or fewer characters): <br> <textarea id="TextArea1" runat="server"/> <br> <input type="submit" value="Submit" runat="server"/> <p> <span id="Span1" runat="server" /> </form> </body> </html>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
HtmlTextArea Class | HtmlTextArea Members | System.Web.UI.HtmlControls Namespace | OnServerChange | System.EventHandler