HtmlSelect.ServerChange 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
서버에 게시되는 사이 HtmlSelect 컨트롤에서 선택된 항목이 변경되면 발생합니다.
public:
event EventHandler ^ ServerChange;
public event EventHandler ServerChange;
member this.ServerChange : EventHandler
Public Custom Event ServerChange As EventHandler
이벤트 유형
예제
다음 코드 예제를 지정 하 고 선언적으로 이벤트 처리기를 코딩 하는 방법을 보여 줍니다는 이벤트에 HtmlSelect 대 한 ServerChange 컨트롤입니다. 이벤트 처리기는 선택한 항목이 서로 호환되는지 여부를 결정합니다.
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Button_Click (Object sender, EventArgs e)
{
Label1.Text = "You selected:";
for (int i=0; i<=Select1.Items.Count - 1; i++)
{
if (Select1.Items[i].Selected)
Label1.Text += "<br /> -" + Select1.Items[i].Text;
}
}
void Server_Change (Object sender, EventArgs e)
{
int Count = 0;
for (int i=0; i<=Select1.Items.Count - 1; i++)
{
if (Select1.Items[i].Selected)
Count++;
}
if ((Count > 1) && (Select1.Items[0].Selected))
Label2.Text = "Hey! You can't select 'All' with another selection!!";
else
Label2.Text = "";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlSelect Example </title>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlSelect Example </h3>
Select items from the list: <br /><br />
<select id="Select1"
multiple="true"
onserverchange="Server_Change"
runat="server">
<option value="All"> All </option>
<option value="1" selected="selected"> Item 1 </option>
<option value="2"> Item 2 </option>
<option value="3"> Item 3 </option>
<option value="4"> Item 4 </option>
<option value="5"> Item 5 </option>
<option value="6"> Item 6 </option>
</select>
<br /><br />
<button id="Button1"
onserverclick="Button_Click"
runat="server">
Submit
</button>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
<br />
<asp:Label id="Label2"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Button_Click (sender As Object, e As EventArgs)
Dim i As Integer
Label1.Text = "You selected:"
For i = 0 to Select1.Items.Count - 1
If Select1.Items(i).Selected Then
Label1.Text = Label1.Text & "<br /> -" & Select1.Items(i).Text
End If
Next
End Sub
Sub Server_Change (sender As Object, e As EventArgs)
Dim i As Integer
Dim Count As Integer = 0
For i = 0 to Select1.Items.Count - 1
If Select1.Items(i).Selected Then
Count = Count + 1
End If
Next
If Count > 1 And Select1.Items(0).Selected Then
Label2.Text = "Hey! You can't select 'All' with another selection!!"
Else
Label2.Text = ""
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlSelect Example </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlSelect Example </h3>
Select items from the list: <br /><br />
<select id="Select1"
multiple="true"
onserverchange="Server_Change"
runat="server">
<option value="All"> All </option>
<option value="1" selected="selected"> Item 1 </option>
<option value="2"> Item 2 </option>
<option value="3"> Item 3 </option>
<option value="4"> Item 4 </option>
<option value="5"> Item 5 </option>
<option value="6"> Item 6 </option>
</select>
<br /><br />
<button id="Button1"
onserverclick="Button_Click"
runat="server">
Submit
</button>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
<br />
<asp:Label id="Label2" runat="server"/>
</div>
</form>
</body>
</html>
다음 코드 예제를 지정 하 고 제어의 이벤트에 대 한 프로그래밍 방식으로 이벤트 처리기를 코딩 하는 ServerChange 방법을 보여 줍니다 HtmlSelect . 이벤트 처리기는 선택한 항목이 서로 호환되는지 여부를 결정합니다.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Button_Click (Object sender, EventArgs e)
{
// Display the selected items.
Label1.Text = "You selected:";
for (int i=0; i<=Select1.Items.Count - 1; i++)
{
if (Select1.Items[i].Selected)
Label1.Text += "<br /> -" + Select1.Items[i].Text;
}
}
void Server_Change(Object sender, EventArgs e)
{
// The ServerChange event is commonly used for data validation.
// This method will display a warning if the "All" option is
// selected in combination with another item in the list.
int Count = 0;
// Determine the number of selected items in the list.
for (int i=0; i<=Select1.Items.Count - 1; i++)
{
if (Select1.Items[i].Selected)
Count++;
}
// Display an error message if more than one item is selected with
// the "All" item selected.
if ((Count > 1) && (Select1.Items[0].Selected))
Label2.Text = "Hey! You can't select 'All' with another selection!!";
else
Label2.Text = "";
}
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.
Select1.ServerChange += new System.EventHandler(this.Server_Change);
Button1.ServerClick += new System.EventHandler(this.Button_Click);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlSelect Server Change Example </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlSelect Server Change Example </h3>
Select items from the list: <br /><br />
<select id="Select1"
multiple="true"
runat="server">
<option value="All"> All </option>
<option value="1" selected="selected"> Item 1 </option>
<option value="2"> Item 2 </option>
<option value="3"> Item 3 </option>
<option value="4"> Item 4 </option>
<option value="5"> Item 5 </option>
<option value="6"> Item 6 </option>
</select>
<br /><br />
<button id="Button1"
runat="server">
Submit
</button>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
<br />
<asp:Label id="Label2"
runat="server"/>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Button_Click (sender As Object, e As EventArgs)
' Display the selected items.
Label1.Text = "You selected:"
Dim i As Integer
For i=0 To Select1.Items.Count - 1
If Select1.Items(i).Selected Then
Label1.Text &= "<br /> -" & Select1.Items(i).Text
End If
Next
End Sub
Sub Server_Change(sender As Object, e As EventArgs)
' The ServerChange event is commonly used for data validation.
' This method will display a warning if the "All" option is
' selected in combination with another item in the list.
Dim Count As Integer = 0
Dim i As Integer
' Determine the number of selected items in the list.
For i=0 To Select1.Items.Count - 1
If Select1.Items(i).Selected Then
Count = Count + 1
End If
Next
' Display an error message if more than one item is selected with
' the "All" item selected.
If ((Count > 1) And (Select1.Items(0).Selected)) Then
Label2.Text = "Hey! You can't select 'All' with another selection!!"
Else
Label2.Text = ""
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 Select1.ServerChange, AddressOf Server_Change
AddHandler Button1.ServerClick, AddressOf Button_Click
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlSelect ServerChange Example </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3> HtmlSelect ServerChange Example </h3>
Select items from the list: <br /><br />
<select id="Select1"
multiple="true"
runat="server">
<option value="All"> All </option>
<option value="1" selected="selected"> Item 1 </option>
<option value="2"> Item 2 </option>
<option value="3"> Item 3 </option>
<option value="4"> Item 4 </option>
<option value="5"> Item 5 </option>
<option value="6"> Item 6 </option>
</select>
<br /><br />
<button id="Button1"
runat="server">
Submit
</button>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
<br />
<asp:Label id="Label2"
runat="server"/>
</div>
</form>
</body>
</html>
설명
이벤트는 ServerChange 컨트롤에서 선택한 항목 HtmlSelect 이 서버에 대한 게시물 간에 변경될 때 발생합니다.
참고
컨트롤의 뷰 상태에 사용할 수 있어야 합니다.는 ServerChange 이벤트가 올바르게 작동 하도록 합니다.
이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET