开发者

Search using Update Panels

Is it possible to use an UpdatePanel that has like a few text boxes, and a search button, and then perhaps another UpdatePanel that has a gridview in it to return the results of what was searched. When the user clicks search it hides the boxes, and displays the gridview. Can I do开发者_如何学Go this with UpdatePanels? I am using c# for my coding. Or should I be doing this another way?


You only need one UpdatePanel in that case and setup a Trigger to your search Button.

Put only the controls that will be refreshed in your UpdatePanel.

Example:

<asp:TextBox ID="txtSearchCriteria" runat="server" />
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
    </Triggers>
    <ContentTemplate>
        <asp:GridView ID="grdSearchResults" runat="server">
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

Implement the btnSearch_Click function to execute your search and bind the results to the GridView. The UpdatePanel will handle the ajax call and replacing of the HTML that the GridView will produce.

You want to keep as much out of the UpdatePanel as possible and only include what will actually change because it is transmitting that HTML with each update so it's a waste of resources if you are not actually doing anything to those controls with each action. That is why a trigger is best to be used in this case which will hook the UpdatePanel to the Click event outside of the UpdatePanel scope.

Read up more on UpdatePanel and how triggers work on MSDN.


If I understand the question correctly, you can do that with two <asp:Panel> controls inside the <UpdatePanel>. One panel for the textboxes, and the other for the gridview. You set which panel to show in the codebehind, depending on whether you're expecting your user to enter search criteria, or review the search results.


Yes you can. You also could use just one update panel. Since you the Search Form (could be in a Panel) and the GridView inside the UpdatePanel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜