2

ScriptManagerコントロールを使用して、AsyncPostbackTriggerとして使用するカスタムイベントをUpdatePanelに登録できますか?

例:

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

ありがとう

4

1 に答える 1

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
于 2012-05-04T06:30:49.830 に答える