HtmlInputRadioButton.OnPreRender(EventArgs) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
引發 PreRender 事件並將 HtmlInputRadioButton 控制項註冊為需要回傳處理的控制項。
protected:
override void OnPreRender(EventArgs ^ e);
protected public:
override void OnPreRender(EventArgs ^ e);
protected override void OnPreRender (EventArgs e);
protected internal override void OnPreRender (EventArgs e);
override this.OnPreRender : EventArgs -> unit
Protected Overrides Sub OnPreRender (e As EventArgs)
Protected Friend Overrides Sub OnPreRender (e As EventArgs)
參數
範例
下列程式碼範例示範如何覆寫 OnPreRender 方法,使其在自訂 HtmlInputRadioButton 伺服器控制項中加入 Title
屬性。
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" 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 - OnPreRender - 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 - OnPreRender - C# Example</h3>
<aspSample:CustomHtmlInputRadioButtonOnPreRender
id="HtmlInputRadioButton1"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio" checked
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton1">HtmlInputRadioButton1
</aspSample:CustomHtmlInputRadioButtonOnPreRender>
<br />
<aspSample:CustomHtmlInputRadioButtonOnPreRender
id="HtmlInputRadioButton2"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio"
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton2">HtmlInputRadioButton2
</aspSample:CustomHtmlInputRadioButtonOnPreRender>
<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.Controls" 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 - OnPreRender - 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 - OnPreRender - Visual Basic Example</h3>
<aspSample:CustomHtmlInputRadioButtonOnPreRender
id="HtmlInputRadioButton1"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio" checked
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton1">HtmlInputRadioButton1
</aspSample:CustomHtmlInputRadioButtonOnPreRender>
<br />
<aspSample:CustomHtmlInputRadioButtonOnPreRender
id="HtmlInputRadioButton2"
name="HtmlInputRadioButtonGroup1"
runat="server"
type="radio"
onserverchange="HtmlInputRadioButtonGroup1_ServerChange"
value="HtmlInputRadioButton2">HtmlInputRadioButton2
</aspSample:CustomHtmlInputRadioButtonOnPreRender>
<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.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomHtmlInputRadioButtonOnPreRender : System.Web.UI.HtmlControls.HtmlInputRadioButton
{
protected override void OnPreRender(System.EventArgs e)
{
// Run the OnPreRender method on the base class.
base.OnPreRender(e);
// Add a Title attribute.
this.Attributes.Add("title", "Option " + this.Value);
}
}
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomHtmlInputRadioButtonOnPreRender
Inherits System.Web.UI.HtmlControls.HtmlInputRadioButton
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
' Run the OnPreRender method on the base class.
MyBase.OnPreRender(e)
' Add a Title attribute.
Me.Attributes.Add("title", "Option " + Me.Value)
End Sub
End Class
備註
方法 OnPreRender 會在轉譯 HtmlInputRadioButton 控制項之前呼叫。
方法 OnPreRender 主要是由控制項開發人員使用,以擴充控制項的功能 HtmlInputRadioButton 。