ValidationSummary.Render Method
.NET Framework 3.0
This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.
Sends server control content to a provided HtmlTextWriter object, which writes the content to be rendered on the client.
Namespace: System.Web.UI.WebControlsAssembly: System.Web (in system.web.dll)
The following code example demonstrates how to override the Render method in a custom server control so that the ValidationSummary control is surrounded by a Small tag.
Security Note: |
|---|
| This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview (Visual Studio). |
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" AutoEventWireup="True" %>
<!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>
<title>Custom ValidationSummary - Render - VJ# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ValidationSummary - Render - VJ# Example</h3>
<table id="Table1" cellpadding="4" cellspacing="0">
<tr>
<td>
<table id="Table2" cellpadding="4" cellspacing="0" style="background-color:#eeeeee">
<tr>
<td colspan="3"><b>Credit Card Information</b> </td>
</tr>
<tr>
<td align="right">Card Type: </td>
<td>
<asp:RadioButtonList id="RadioButtonList1" runat="server" RepeatLayout="Flow">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>
</td>
<td align="center" rowspan="1">
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
runat="server"
ErrorMessage="Card Type"
Width="100%"
Display="Static"
ControlToValidate="RadioButtonList1">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">Card Number: </td>
<td><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
runat="server"
ErrorMessage="Card Number"
Width="100%"
Display="Static"
ControlToValidate="TextBox1">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="Button1" runat="server" text="Validate"></asp:Button></td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<aspSample:CustomValidationSummaryRender
id="ValidationSummary1"
runat="server"
DisplayMode="BulletList"
HeaderText="You must enter a value in the following fields:" />
</td>
</tr>
</table>
</form>
</body>
</html>
...
package Samples.AspNet.JSL.Controls;
public class CustomValidationSummaryRender
extends System.Web.UI.WebControls.ValidationSummary
{
protected void Render(System.Web.UI.HtmlTextWriter writer)
{
// Write out begining Small HTML tag.
writer.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Small);
// Call the base class's Render method.
super.Render(writer);
// Write out ending Small HTML tag.
writer.RenderEndTag();
} //Render
} //CustomValidationSummaryRender
Community Additions
ADD
Show:
Security Note: