HtmlInputRadioButton.RenderAttributes(HtmlTextWriter) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 HtmlInputRadioButton 控件特性呈现给指定的 HtmlTextWriter 对象。
protected:
override void RenderAttributes(System::Web::UI::HtmlTextWriter ^ writer);
protected override void RenderAttributes (System.Web.UI.HtmlTextWriter writer);
override this.RenderAttributes : System.Web.UI.HtmlTextWriter -> unit
Protected Overrides Sub RenderAttributes (writer As HtmlTextWriter)
参数
- writer
- HtmlTextWriter
接收呈现输出的 HtmlTextWriter。
示例
下面的代码示例演示如何重写 RenderAttributes 自定义服务器控件中的方法,以便始终显示 HtmlInputRadioButton特定的标题文本。
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Samples" Assembly="Samples.AspNet.CS" %>
<!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 HtmlInputRadioButton - RenderAttributes - C# Example</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
Div1.InnerHtml = "";
}
void HtmlInputRadioButtonGroup1_ServerChange(object sender, System.EventArgs e)
{
// Diplay the value of the selected HtmlInputRadioButton control.
System.Web.UI.HtmlControls.HtmlInputRadioButton htmlInputRadioButtonGroup1 = (System.Web.UI.HtmlControls.HtmlInputRadioButton) sender;
Div1.InnerHtml = "You change your selection to: " + htmlInputRadioButtonGroup1.Value;
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom HtmlInputRadioButton - Method - C# RenderAttributes</h3>
<aspSample:CustomHtmlInputRadioButtonRenderAttributes
id="HtmlInputRadioButton1"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio" checked
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton1">HtmlInputRadioButton1
</aspSample:CustomHtmlInputRadioButtonRenderAttributes>
<br />
<aspSample:CustomHtmlInputRadioButtonRenderAttributes
id="HtmlInputRadioButton2"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio"
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton2">HtmlInputRadioButton2
</aspSample:CustomHtmlInputRadioButtonRenderAttributes><br />
<p>
<input type="submit" value="Submit" id="Submit1" name="Submit1" runat="server" />
</p>
<div
id="Div1"
runat="server"
style="DISPLAY: inline; WIDTH: 256px; HEIGHT: 15px" />
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Samples" Assembly="Samples.AspNet.VB" %>
<!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 HtmlInputRadioButton - RenderAttributes - Visual Basic Example</title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Div1.InnerHtml = ""
End Sub
Sub HtmlInputRadioButtonGroup1_ServerChange(sender As Object, e As System.EventArgs)
Dim htmlInputRadioButtonGroup1 As System.Web.UI.HtmlControls.HtmlInputRadioButton = CType(sender, System.Web.UI.HtmlControls.HtmlInputRadioButton)
Div1.InnerHtml = "You change your selection to: " & htmlInputRadioButtonGroup1.Value
End Sub
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom HtmlInputRadioButton - Method - Visual Basic RenderAttributes</h3>
<aspSample:CustomHtmlInputRadioButtonRenderAttributes
id="HtmlInputRadioButton1"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio" checked
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton1">HtmlInputRadioButton1
</aspSample:CustomHtmlInputRadioButtonRenderAttributes>
<br />
<aspSample:CustomHtmlInputRadioButtonRenderAttributes
id="HtmlInputRadioButton2"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio"
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton2">HtmlInputRadioButton2
</aspSample:CustomHtmlInputRadioButtonRenderAttributes><br />
<p>
<input type="submit" value="Submit" id="Submit1" name="Submit1" runat="server" />
</p>
<div
id="Div1"
runat="server"
style="DISPLAY: inline; WIDTH: 256px; HEIGHT: 15px" />
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Samples
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomHtmlInputRadioButtonRenderAttributes : System.Web.UI.HtmlControls.HtmlInputRadioButton
{
protected override void RenderAttributes(System.Web.UI.HtmlTextWriter writer)
{
// Call the base class's RenderAttributes method.
base.RenderAttributes(writer);
// Write out the control's Title tag.
writer.Write(" Title=\"Option " + this.Value + "\"");
}
}
}
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Samples
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomHtmlInputRadioButtonRenderAttributes
Inherits System.Web.UI.HtmlControls.HtmlInputRadioButton
Protected Overrides Sub RenderAttributes(ByVal writer As System.Web.UI.HtmlTextWriter)
' Call the base class's RenderAttributes method.
MyBase.RenderAttributes(writer)
' Write out the control's Title tag.
writer.Write((" Title=""Option " + Me.Value + """"))
End Sub
End Class
End Namespace
注解
该方法 RenderAttributes 将 Value 属性写入控件的属性 HtmlInputRadioButton ,然后调用基类 RenderAttributes 的方法
该方法 RenderAttributes 主要用于控件开发人员扩展控件的功能 HtmlInputRadioButton 。