UpdatePanel并将消息发布到其他控件

时间:2012-05-04 01:51:51

标签: c# asp.net ajax updatepanel ajaxcontroltoolkit

我可以使用ScriptManager控件注册自定义事件以用作具有UpdatePanel的AsyncPostbackTrigger吗?

示例:

<Triggers>
        <asp:AsyncPostBackTrigger  ControlID="ucTest"  EventName="CustomEvent" />
</Triggers>

由于

1 个答案:

答案 0 :(得分:0)

检查此示例:

TextControl.ascx

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="TextControl.ascx.vb" Inherits="TextControl" %>
<asp:Button ID="button1" runat="server" Text="Text" />

TextControl.ascx.vb

Partial Class TextControl
    Inherits System.Web.UI.UserControl

    Public Event ButtonClick(ByVal sender As Object, ByVal e As _
     System.EventArgs)

    Private Sub button1_onclick(ByVal sender As Object, ByVal e As _
     System.EventArgs) Handles button1.Click

        RaiseEvent ButtonClick(sender, e)

    End Sub

End Class

ctrlPage.aspx(使用控件的地方)

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ctrlPage.aspx.vb" Inherits="ctrlPage" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<%@ Register Src="TextControl.ascx" TagName="wTextC" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="scr1" runat="server">
        </asp:ScriptManager>
    <div>
    <uc1:wTextC ID="wMenu1" runat="server" />
        <asp:UpdatePanel ID="upd1" runat="server">
        <ContentTemplate>
            <asp:Label runat="server" Text="" ID="label1"></asp:Label>
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="wMenu1" EventName="ButtonClick" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

ctrlPage.aspx.vb

Partial Class ctrlPage
    Inherits System.Web.UI.Page

    Protected Sub wMenu1_ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles wMenu1.ButtonClick
        Me.label1.Text = ":)"
    End Sub   

End Class