将事件添加到Web用户控件 [英] To add event to Web user control

查看:85
本文介绍了将事件添加到Web用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下声明将名为TestUserControl.ascx的Web用户控件添加到名为TestPage.aspx的ASP.NET

页面。

< uc:TestUserControl ID =testControlrunat =server/>

您将以下代码添加到TestPage.aspx的代码隐藏文件中。

private void TestMethod()

{。

..

}

你定义以下代表。

public delegate void MyEventHandler();

您需要将名为MyEvent的MyEventHandler类型的事件添加到TestUserControl.ascx并将

页面的TestMethod方法附加到事件。

你应该执行哪两项行动? (每个正确答案都是解决方案的一部分。选择两个。)

A.将以下代码行添加到TestUserControl.ascx.cs。

公共事件MyEventHandler MyEvent;

B.将以下代码行添加到TestUserControl.ascx.cs。

public MyEventHandler MyEvent;

C.替换TestUserControl.ascx使用以下声明在TestPage.aspx中引用。

< uc:TestUserControl ID =testControlrunat =server
$ b $bönMyEvent=TestMethod/>

D.使用以下声明替换TestPage.aspx中的TestUserControl.ascx引用。

< uc:TestUserControl ID =testControlrunat =server

MyEvent =TestMethod/>



另外OnMyEvent和MyEventin之间有什么区别选项C&D ????

You use the following declaration to add a Web user control named TestUserControl.ascx to an ASP.NET
page named TestPage.aspx.
<uc:TestUserControl ID="testControl" runat="server"/>
You add the following code to the code-behind file of TestPage.aspx.
private void TestMethod()
{.
..
}
You define the following delegate.
public delegate void MyEventHandler();
You need to add an event of type MyEventHandler named MyEvent to TestUserControl.ascx and attach the
page''s TestMethod method to the event.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Add the following line of code to TestUserControl.ascx.cs.
public event MyEventHandler MyEvent;
B. Add the following line of code to TestUserControl.ascx.cs.
public MyEventHandler MyEvent;
C. Replace the TestUserControl.ascx reference in TestPage.aspx with the following declaration.
<uc:TestUserControl ID="testControl" runat="server"
önMyEvent="TestMethod"/>
D. Replace the TestUserControl.ascx reference in TestPage.aspx with the following declaration.
<uc:TestUserControl ID="testControl" runat="server"
MyEvent="TestMethod"/>

Also What is the difference between OnMyEvent and MyEventin Options C & D????

推荐答案

如何为a创建事件用户控制 [ ^ ]


这篇关于将事件添加到Web用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆