1

我有下面的代码,看起来应该可以工作。但是,引用controlID为“gvSearch”的控件的触发器实际上是用户控件页面内的gridview。

如何访问该网格视图以便可以将其用作触发器?

谢谢!

<asp:UpdatePanel ID="pnlSearch" ChildrenAsTriggers="true" runat="server" >
      <Triggers>
          <asp:AsyncPostBackTrigger ControlID="btnSearch" />
          <asp:AsyncPostBackTrigger ControlID="gvSearch" />
      </Triggers>
</asp:UpdatePanel>

谢谢!

大纲:

<%@ Page Title="test">
<%@ Register src="test1.ascx" tagname="test1" tagprefix="test1uc" %>
    <UpdatePanel>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnSearch" />
            <asp:AsyncPostBackTrigger ControlID="gvSearch" />
        </Triggers>
        <ContentTemplate>
             <test1uc:test1 ID="test1a" runat="server" />
        </ContentTemplate>
    </UpdatePanel>
4

2 回答 2

2

你想用什么事件作为触发器,SelectedIndexChanged-event?然后应用适当的EventName.

<asp:AsyncPostBackTrigger ControlID="gvSearch" EventName="SelectedIndexChanged" />

但是,这应该已经是默认事件GridView(请参阅remarks章节)。

看看这个线程:http ://forums.asp.net/t/1136932.aspx

更新我认为在您的情况下最好的方法是在您的 UserControl 中提供一个自定义事件,该SelectedIndexChanged事件是从GridViewUC 中的事件中冒出来的。然后你可以使用这个事件作为AsyncPostBackTrigger你的UpdatePanel,例如:

<asp:AsyncPostBackTrigger ControlID="test1a" EventName="GridSearchClicked" />
于 2013-02-20T21:15:11.130 回答
1

撇开需要访问子控件不是好习惯的事实不谈,这是我最好的建议......

在您的用户控件中创建一个Public Sub,如下所示:

Private ParentUpdatePanel As System.Web.UI.UpdatePanel

' Must be called on every Page_Load!
Public Sub RegisterAsyncTrigger(MyScriptManager As System.Web.UI.ScriptManager, MyUpdatePanel As System.Web.UI.UpdatePanel)
    MyScriptManager.RegisterAsyncPostBackControl(gvSearch)
    ParentUpdatePanel = MyUpdatePanel
End Sub

在 Page_Load 事件中,您将按如下方式调用该函数:

Protected Sub Page_Load(Sender As Object, e As EventArgs)
    ' Call our new function, passing in the current ScriptManager and the UpdatePanel
    ' The ScriptManager handles the asynchronous postbacks
    ' The UpdatePanel handles the dynamic updates
    test1.RegisterAsyncTrigger(ScriptManager.GetCurrent(Me), pnlSearch)
End Sub

在必须更新面板的 GridView 控件内的事件处理程序中,gvSearch将包含以下代码:

ParentUpdatePanel.Update()
于 2013-02-20T21:56:36.533 回答