问题
I have seen this question before, but none of the answers seems to work for me. This is my updatePanel section (inside hi.ascx):
<asp:UpdatePanel runat="server" ID="upUL" UpdateMode="Conditional" >
<ContentTemplate>
...
<Angel:Pager id="pager" runat="server" OnPageClicked="Pager_PageSelected" />
<!--End of control div-->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbBlock" />
<asp:AsyncPostBackTrigger ControlID="lbUnblock" />
<asp:AsyncPostBackTrigger ControlID="pager" EventName="PageClicked" />
</Triggers>
</asp:UpdatePanel>
Now this is the code within the Pager.ascx.vb:
Public Delegate Sub ClickPage(sender As Object, e As PageClickedEventArgs)
Public Event PageClicked As ClickPage
Public Class PageClickedEventArgs
Inherits EventArgs
Public Property PageNumber() As Integer
End Class
....
Protected Sub rpPaging_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim pageNum As Integer
Integer.TryParse(e.CommandArgument.ToString(), pageNum)
If (pageNum <> 0) Then
Dim args As New PageClickedEventArgs
args.PageNumber = pageNum
RaiseEvent PageClicked(sender, args)
End If
'SelectNewPage(pageNum)
End Sub
And finally, this is my code on the hi.ascx.vb page:
Public Sub Pager_PageSelected(sender As Object, ByVal e As Paging.PageClickedEventArgs)
BindData(False, e.PageNumber)
End Sub
As I stated in the title. When I raise an event from the pager.ascx, it causes a full post back(and works great but I wanted it to be in Ajax).
The other controls(LinkButtons) within this updatepanel like lbBlock and lbUnblock , are working great and not causing full postback!
Please please help me. I spent too much time on it and nothing seems to work!
thanks,
Ran
回答1:
That solved the problem:
Protected Sub rpPaging_onItemCreated(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
Dim lb = e.Item.FindControl("lbPage")
If lb IsNot Nothing Then _
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(lb)
End Sub
Apparently, Controls within a repeater would not register themselves automatically... So i needed to add each one of them to the scriptmanager!
Hope it would help to someone out there...
回答2:
asp.net would not know how to track your PageClicked
event on the client side. So firing the conditional trigger would not happen.
If this event corresponds to the event of a button or linkbutton in your custom control, expose that event, and the update panel will use that to track the event on client side.
Not quite used to VB, this is how you expose an event in c#
public event EventHandler PageChanged
{
add { grd.PageChanged += value; }
remove { grd.PageChanged -= value; }
}
来源:https://stackoverflow.com/questions/11652487/updatepanel-causing-full-postback-with-usercontrol-custom-events