2012-03-06 3 views
0

두 개의 ASP : 버튼이 있습니다. button1과 button2라고 말하고 싶습니다. button1을 클릭하면 fire button2의 클릭 이벤트가 발생합니다. 코드 숨김을 통해 asp : button에서 click 이벤트를 발생 시키시겠습니까? 제발 도와 줘, 초보자.트리거 asp : 다른 asp : button을 클릭하여 버튼의 클릭 이벤트

+2

button2에 대한 논리를 별도의 메서드에 넣으면 button1에서도 호출 할 수 있습니다. – bschultz

답변

0

글쎄, 당신은 다음과 같이 두 버튼에 뭔가를 같은 이벤트를 넣을 수 있습니다 :

<asp:Button ID="btn1" runat="server" Text="Button 1" CommandName="Save" /> 
<asp:Button ID="btn2" runat="server" Text="Button 2" CommandName="Cancel" /> 

뒤에 코드 (vb.net)에서 :

Protected Sub btn_event(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click 

    Dim btn As Button = CType(sender, Button) 

    'now you have the button instance on sender object, and you can check the ID property or CommandName property do solve what you want to do! 

End Sub 

C# 코드 :

protected void btn_event(object sender, EventArgs e) { 

    Button btn = (Button)sender; 

    //now you have the button instance on sender object, and you can check the ID property or CommandName property do solve what you want to do! 

} 

C#을 사용하는 경우 asp : button 태그에서 이벤트 클릭을 설정해야합니다.

+0

선생님, 지금 일하고 있습니다. 처음에는 미안 했어요. 초보자는 여기에. –

관련 문제