HtmlForm.DefaultButton 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
Enter 키를 누를 때 포스트백을 HtmlForm 발생시키는 컨트롤의 자식 컨트롤을 가져오거나 설정합니다.
public:
property System::String ^ DefaultButton { System::String ^ get(); void set(System::String ^ value); };
public string DefaultButton { get; set; }
member this.DefaultButton : string with get, set
Public Property DefaultButton As String
속성 값
ID 로드될 때 기본 단추로 표시할 단추 컨트롤입니다HtmlForm. 기본값은 빈 문자열("")입니다.
예외
기본 단추로 참조되는 컨트롤이 형식 IButtonControl이 아닙니다.
예제
다음 예제에서는 포스트백을 DefaultButton 발생 시키는 기본 컨트롤을 설정 하는 속성을 설정 하는 방법을 보여 있습니다.
<%@ 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 Page_Load(object sender, System.EventArgs e)
{
// Set the text of the two label controls.
Label1.Text = "The DefaultButton property is set to "
+ Form1.DefaultButton.ToString() + "<br/>";
Label2.Text = "The DefaultFocus property is set to "
+ Form1.DefaultFocus.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlForm DefaultButton and DefaultFocus Properties Example</title>
</head>
<body>
<form id="Form1"
defaultbutton="SubmitButton"
defaultfocus="TextBox1"
runat="server">
<h3>HtmlForm DefaultButton and DefaultFocus Properties Example</h3>
TextBox1:
<asp:textbox id="TextBox1"
autopostback="true"
runat="server">
</asp:textbox>
<br />
TextBox2:
<asp:textbox id="TextBox2"
autopostback="true"
runat="server">
</asp:textbox>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
runat="server">
</asp:button>
<asp:button id="CancelButton"
text="Cancel"
runat="server">
</asp:button>
<hr />
<asp:label id="Label1"
runat="Server">
</asp:label>
<asp:label id="Label2"
runat="Server">
</asp:label>
</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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Set the text of the two label controls.
Label1.Text = "The DefaultButton property is set to " _
& Form1.DefaultButton.ToString & "<br/>"
Label2.Text = "The DefaultFocus property is set to " _
& Form1.DefaultFocus.ToString
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlForm DefaultButton and DefaultFocus Properties Example</title>
</head>
<body>
<form id="Form1"
defaultbutton="SubmitButton"
defaultfocus="TextBox1"
runat="server">
<h3>HtmlForm DefaultButton and DefaultFocus Properties Example</h3>
TextBox1:
<asp:textbox id="TextBox1"
autopostback="true"
runat="server">
</asp:textbox>
<br />
TextBox2:
<asp:textbox id="TextBox2"
autopostback="true"
runat="server">
</asp:textbox>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
runat="server">
</asp:button>
<asp:button id="CancelButton"
text="Cancel"
runat="server">
</asp:button>
<hr />
<asp:label id="Label1"
runat="Server">
</asp:label>
<asp:label id="Label2"
runat="Server">
</asp:label>
</form>
</body>
</html>
설명
이 DefaultButton 속성을 사용하면 사용자가 폼의 입력 컨트롤(예: 텍스트 상자)에서 Enter 키를 눌러 포스트백을 발생시킬 수 있도록 지정할 수 있습니다. 컨트롤을 제외한 LinkButton 인터페이스에서 파생되는 모든 컨트롤을 IButtonControl 기본 단추로 지정할 수 있습니다. 속성에서 참조 DefaultButton 하는 컨트롤이 파생 IButtonControl되지 않으면 예외가 InvalidOperationException throw됩니다.
마스터 페이지를 사용하고 콘텐츠 페이지에서 속성을 설정하는 DefaultButton 경우 단추의 UniqueIDIButtonControl 속성을 사용합니다. 마스터 페이지에 대한 자세한 내용은 ASP.NET 마스터 페이지를 참조하세요.
이 속성은 DefaultButton 다음 시나리오에서 포스트백을 일으키지 않을 수 있습니다.
폼의 입력 컨트롤 외부에 포커스가 있을 때 Enter 키를 누릅니다. 기본 포스트백 동작은 트리거되지 않습니다.
포커스가 여러 줄 텍스트 상자 안에 있을 때 Enter 키를 누릅니다. 여러 줄 텍스트 상자에서 예상되는 동작은 Enter 키를 누르면 텍스트 상자에 새 줄이 만들어지는 것입니다. 일부 브라우저에서는 여러 줄 텍스트 상자 내에서 Enter 키를 누르면 포스트백이 트리거됩니다. 이 경우 Enter 키를 눌러 새 줄을 만들려면 JavaScript 함수를 입력 컨트롤에 연결할 수 있습니다. 스크립트는 ENTER 키를 캡처하고 포스트백을 중지해야 합니다. 예를 들어 속성 컬렉션을 사용하여 Attributes 이벤트에 대한 클라이언트 스크립트를
onKeyPress추가할 수 있습니다.컨트롤을 LinkButton 기본 단추로 지정합니다. ImageButton 컨트롤만 Button 지원됩니다.
비동기 DefaultButton 포스트백 중에 프로그래밍 방식으로 속성을 변경합니다. 페이지에 하나 이상의 UpdatePanel 컨트롤을 추가하여 페이지에서 비동기 포스트백을 사용하도록 설정할 수 있습니다. 자세한 내용은 UpdatePanel 컨트롤 개요 및 Partial-Page 렌더링 개요를 참조하세요.