我有一个带有两个按钮的usercontroll,我想在我调用usercontrol的页面中获取raiseevent。一切正常,但是当我点击用户控件上的按钮时我无法捕捉到该事件。
我的uc标记:
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
在我的页面中,这是一个带有更新面板的母版页的竞赛页面我尝试在后面的代码中跟踪事件
<msg:PopInfoMsg ID="PopMsg" runat="server" />
在页面上的标记中,我将控件直接置于UpdatePanel的ContentTemplate后面
Protected Sub HelpMsg()
PopMsg.MsgText = "My first Test<br/> Cheers<br/>"
PopMsg.Pop("", "IconInfo", "Info")
End Sub
点击按钮
呼叫UCfunction getRow(svcName, rowId)
{
// Mark in progress
$("#" + rowId).html("<td colspan='5'>" + svcName + "<i class='fa fa-refresh fa-spin fa-1x fa-fw'></i></td>").addClass('info');
// Get the HTML
$.ajax(
{
type: 'get',
dataType: 'html',
url: svcName,
error: function (jqXHR, textStatus, errorText) {
$("#" + rowId).text("Error " + errorText + " (" + svcName + ")");
var row = $(".service-table").DataTable().row("#" + rowId);
row.invalidate('dom');
},
success: function (response, textStatus, jqXHR) {
// This response is visible in the table
// UNTIL I sort the table, at which time it's the temporary
// version of the row, above, which is restored
// from the dataTable cache.
$("." + rowId).replaceWith(response);
var row = $(".service-table").DataTable().row("#" + rowId);
row.invalidate('dom');
//row.draw('row');
}
}
);
}
控件按预期打开,但是单击“确定”按钮时控件关闭而没有事件。 在VS中,我尝试在Button Click上进行调试,但代码没有运行到这一点。 哪里错了?最后几天让我感到困惑......
干杯,亚历克斯