0

我有一个带有两个按钮的用户控件,我想在调用用户控件的页面中获取 raiseevent。一切正常,除了当我单击用户控件上的按钮时我无法捕捉到事件。

我对 uc 的标记:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MsgBox.ascx.vb" Inherits="MsgBox" ClassName="MsgBox" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
<style type="text/css">
    .Modal_trans {
        opacity: 0.8;
        filter: alpha(opacity=60);
    }
</style>
<link rel="stylesheet" type="text/css" href="../Styles/StyleSheet.css" />"
<asp:Panel ID="PopPanel" runat="server" 
    Width="500px" Height="50px" DefaultButton="ok" Style="overflow:hidden;" CssClass="ModalGrid">
    <table style="width: 100%; border-collapse: collapse; border: 0px;">
        <tr id="boxheader" runat="server" style="cursor: move;">
            <th colspan="2" style="padding-left: 10px; padding-top: 3px; padding-bottom: 3px;">
                <asp:Label ID="lblTitle" runat="server" Text="Help"></asp:Label>
            </th>
        </tr>
        <tr>
            <td>
                <asp:Image ID="Image" runat="server" ImageUrl="../images/info.png" />
            </td>
            <td style="padding: 10px; width: 220px;">
                <div style="width: 295px; height:70px;"">
                    <asp:Label ID="lblMsg" runat="server" BackColor="#CCCCCC"  />
                </div>
            </td>
        </tr>
        <tr>
            <th colspan="2" style="padding-right: 20px; padding-top: 7px; padding-bottom: 7px;"" >
                <asp:LinkButton ID="LinkButton1" runat="server" Style="display:none" ></asp:LinkButton>
                <asp:Button ID="ok" runat="server" Text="Ok" Width="80px"  />
                <asp:Button ID="no" runat="server" Text="No / Cancel" Width="80px" Visible="False" />
            </th>
        </tr>
    </table>
</asp:Panel>
<act:ModalPopupExtender ID="PopUp" runat="server" Enabled="True"
    PopupControlID="PopPanel" TargetControlID="LinkButton1" BackgroundCssClass="Modal_trans"
    OkControlID="ok" PopupDragHandleControlID="boxheader" Y="0" DropShadow="True">
    <Animations>
        <OnShown>
            <Sequence AnimationTarget="PopPanel">
                <Parallel Duration=".5" Fps="25">
                    <Move Horizontal="-175" Vertical="200" />
                    <Resize Width="350" Height="142"/>
                    <FadeIn />
                </Parallel>
            </Sequence>
        </OnShown>
        <OnHiding>
            <Sequence AnimationTarget="PopPanel">
                <%-- Scale the flyout down to 5% to make it disappear --%>
                <Parallel Duration=".75" Fps="25">
                    <Scale ScaleFactor="0.05" Center="true" ScaleFont="true" FontUnit="px" />
                    <FadeOut />
                </Parallel>
                <%-- Reset the styles on the info box --%>
                <StyleAction Attribute="display" Value="none"/>
                <StyleAction Attribute="width" Value="350px"/>
                <StyleAction Attribute="height" Value=""/>
                <StyleAction Attribute="fontSize" Value="12px"/>
                <%-- Re-enable the button --%>
                <EnableAction Enabled="true" AnimationTarget="ok" />
            </Sequence>
        </OnHiding>
    </Animations>
</act:ModalPopupExtender>

和背后的代码

    Partial Class MsgBox
    Inherits System.Web.UI.UserControl
    Public Shared IconInfo, IconExec, IconQues, IconError As Object
    Public Property MsgText As String
        Get
            Return lblMsg.Text
        End Get
        Set(ByVal value As String)
            lblMsg.Text = value
        End Set
    End Property
    Public Event MsgButtonClick(ByVal buttonName As String)
    Protected Sub MsgButtonOKClick(ByVal sender As Object, ByVal e As EventArgs) Handles ok.Click
        RaiseEvent MsgButtonClick("ok")
    End Sub
    Protected Sub MsgButtonDenyClick(ByVal sender As Object, ByVal e As EventArgs) Handles no.Click
        RaiseEvent MsgButtonClick("no")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        IconInfo = "Show Information Icon"
        IconExec = "Show Warning Icon"
        IconQues = "Show Question Icon"
        IconError = "Show Error Icon"
    End Sub
    Public Sub Pop(Optional ByVal Message As String = "", Optional ByVal Mode As Object = "IconInfo", Optional ByVal Title As String = "Info Message")

        no.Visible = False
        ok.Text = "Ok"

        If Title <> "" Then
            lblTitle.Text = Title
        End If

        Select Case Mode
            Case "IconInfo"
                Image.ImageUrl = "../images/info.png"
                no.Visible = False
                ok.Text = "Ok"
                lblTitle.Text = "Info"
            Case "IconExec"
                Image.ImageUrl = "../images/exc.png"
                no.Visible = False
                ok.Text = "Ok"
                lblTitle.Text = "Warning"
            Case "IconQues"
                Image.ImageUrl = "../images/ques.png"
                no.Visible = True
                ok.Text = "Yes"                    lblTitle.Text = "Question"
            Case "IconError"
                Image.ImageUrl = "../images/error.png"
                no.Visible = False
                ok.Text = "Ok"
                lblTitle.Text = "Error"
        End Select

        PopUp.Show()
    End Sub

    Protected Sub No_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles no.Click
        PopUp.Hide()
    End Sub

也测试了变化

    Public Event MsgButtonClick As EventHandler
Protected Sub MsgButtonOKClick(ByVal sender As Object, ByVal e As EventArgs) Handles ok.Click
    RaiseEvent MsgButtonClick(sender, e)
End Sub
Protected Sub MsgButtonDenyClick(ByVal sender As Object, ByVal e As EventArgs) Handles no.Click
    RaiseEvent MsgButtonClick(sender, e)
End Sub

在我的页面中,它是带有更新面板的母版页的内容页面,我尝试通过后面的代码来捕捉事件

Protected Sub test() Handles PopMsg.MsgButtonClick
    Response.Write("Done")
End Sub

在页面上的标记中,我将控件直接放在 UpdatePanel 的 ContentTemplate 后面

<msg:PopInfoMsg ID="PopMsg" runat="server" />

并通过单击按钮调用 UC

Protected Sub HelpMsg()
    PopMsg.MsgText = "My first Test<br/> Cheers<br/>"
    PopMsg.Pop("", "IconInfo", "Info")
End Sub

控件按预期打开,但是当单击“确定”按钮时,控件在没有事件的情况下关闭。在 VS 中,我尝试在 Button Click 处进行调试,但代码没有运行到这一点。我哪里错了?最近几天让我很困惑...

干杯,亚历克斯

4

0 回答 0