input+html+change,HtmlInputRadioButton

Occurs when the value of the Checked property of the HtmlInputRadioButton control changes between posts to the server.

public:

event EventHandler ^ ServerChange;

public event EventHandler ServerChange;

member this.ServerChange : EventHandler

Public Custom Event ServerChange As EventHandler

事件類型

範例

下列程式碼範例示範如何指定事件的處理常式,並為其撰寫程式碼 ServerChange 。The following code example demonstrates how to specify and code a handler for the ServerChange event. 自訂事件處理常式會更新網頁上的標籤,以顯示所選取之選項按鈕的值。The custom event handler updates a label on the Web page to display the value of the selected radio button.

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HtmlInputRadioButton Sample

void Server_Change(object sender, EventArgs e)

{

if (Radio1.Checked)

Span1.InnerHtml = "You selected " +

Radio1.Value;

else if (Radio2.Checked)

Span1.InnerHtml = "You selected " +

Radio2.Value;

else if (Radio3.Checked)

Span1.InnerHtml = "You selected " +

Radio3.Value;

}

HtmlInputRadioButton Sample

id="Radio1"

name="Mode"

value="Radio Button 1"

onserverchange="Server_Change"

runat="server"/>

Option 1

id="Radio2"

name="Mode"

value="Radio Button 2"

onserverchange="Server_Change"

runat="server"/>

Option 2

id="Radio3"

name="Mode"

value="Radio Button 3"

onserverchange="Server_Change"

runat="server"/>

Option 3

id="Button1"

value="Submit"

runat="server"/>

runat="server" />

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HtmlInputRadioButton Sample

Sub Server_Change(sender As Object , e As EventArgs)

If Radio1.Checked Then

Span1.InnerHtml = "You selected " & _

Radio1.Value

ElseIf Radio2.Checked Then

Span1.InnerHtml = "You selected " & _

Radio2.Value

ElseIf Radio3.Checked Then

Span1.InnerHtml = "You selected " & _

Radio3.Value

End If

End Sub

HtmlInputRadioButton Sample

id="Radio1"

name="Mode"

value="Radio Button 1"

onserverchange="Server_Change"

runat="server"/>

Option 1

id="Radio2"

name="Mode"

value="Radio Button 2"

onserverchange="Server_Change"

runat="server"/>

Option 2

id="Radio3"

name="Mode"

value="Radio Button 3"

onserverchange="Server_Change"

runat="server"/>

Option 3

id="Button1"

value="Submit"

runat="server"/>

runat="server"/>

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HtmlInputRadioButton ServerChange Example

void Server_Change(object sender, EventArgs e)

{

if (Radio1.Checked)

{

Span1.InnerHtml = "You selected " + Radio1.Value;

}

else if (Radio2.Checked)

{

Span1.InnerHtml = "You selected " + Radio2.Value;

}

else if (Radio3.Checked)

{

Span1.InnerHtml = "You selected " + Radio3.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.

Radio1.ServerChange += new System.EventHandler(this.Server_Change);

Radio2.ServerChange += new System.EventHandler(this.Server_Change);

Radio3.ServerChange += new System.EventHandler(this.Server_Change);

}

HtmlInputRadioButton ServerChange Example

id="Radio1"

name="Mode"

value="Radio Button 1"

runat="server"/>

Option 1

id="Radio2"

name="Mode"

value="Radio Button 2"

runat="server"/>

Option 2

id="Radio3"

name="Mode"

value="Radio Button 3"

runat="server"/>

Option 3

id="Button1"

value="Submit"

runat="server"/>

runat="server" />

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HtmlInputRadioButton ServerChange Example

Sub Server_Change(sender As Object, e As EventArgs)

If Radio1.Checked Then

Span1.InnerHtml = "You selected " & Radio1.Value

ElseIf Radio2.Checked Then

Span1.InnerHtml = "You selected " & Radio2.Value

ElseIf Radio3.Checked Then

Span1.InnerHtml = "You selected " & Radio3.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 Radio1.ServerChange, AddressOf Server_Change

AddHandler Radio2.ServerChange, AddressOf Server_Change

AddHandler Radio3.ServerChange, AddressOf Server_Change

End Sub

HtmlInputRadioButton ServerChange Example

id="Radio1"

name="Mode"

value="Radio Button 1"

runat="server"/>

Option 1

id="Radio2"

name="Mode"

value="Radio Button 2"

runat="server"/>

Option 2

id="Radio3"

name="Mode"

value="Radio Button 3"

runat="server"/>

Option 3

id="Button1"

value="Submit"

runat="server"/>

runat="server" />

備註

The ServerChange event is raised when the Checked property of the HtmlInputRadioButton control changes value between posts to the server. 這可讓您建立自訂事件處理常式,以執行一組特定的指令 (例如引發事件時的資料驗證) 。This allows you to create a custom event handler that performs a specific set of instructions (such as data validation) when the event is raised.

注意

控制項必須啟用 [view] 狀態, ServerChange 事件才能正確運作。The control must have view state enabled for the ServerChange event to work correctly. 若要啟用 Web Form 頁面上所有控制項的檢視狀態,請將 Page.EnableViewState 屬性設定為 true 。To enable view state for all controls on the Web Forms page, set the Page.EnableViewState property to true. 您也可以藉由將屬性設定為,來啟用個別控制項的 [view state] Control.EnableViewState true 。You can also enable view state for an individual control by setting the Control.EnableViewState property to true.

如需如何處理事件的詳細資訊,請參閱 處理和引發事件。For more information about how to handle events, see Handling and Raising Events.

適用於

另請參閱

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值