i have a usercontroll with two buttons and i want to get the raiseevent in the page where i call the usercontrol. Everything works fine except that i can't catch the event when i click the button on the user contol.
my markup for the 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>
and the code behind
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
Tested also with the variation
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
In my page, it's a contetpage of a master page with update panel i try to catch the event with following in the code behind
Protected Sub test() Handles PopMsg.MsgButtonClick
Response.Write("Done")
End Sub
In the markup on the page i have placed the controldirectly behind the ContentTemplate of the UpdatePanel
<msg:PopInfoMsg ID="PopMsg" runat="server" />
And call the UC with a button click
Protected Sub HelpMsg()
PopMsg.MsgText = "My first Test<br/> Cheers<br/>"
PopMsg.Pop("", "IconInfo", "Info")
End Sub
The control open as expected, but when clicking the "OK" button the control close without an event. In VS i tried to debug at the Button Click but the code doesn't run to this point. Where i'am wrong? Confusing me the last days...
Cheers, Alex