更新面板并将消息发布到其他控件

本文关键字:其他 控件 消息 更新 | 更新日期: 2023-09-27 18:33:12

是否可以使用 ScriptManager 控件向 UpdatePanel 注册要用作 AsyncPostbackTrigger 的自定义事件?

例:

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

谢谢

更新面板并将消息发布到其他控件

检查这个例子:

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

ctrl页面.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>

ctrl页面.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