In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to achieve forum topic search in ASP.NET AJAX". In daily operation, I believe many people have doubts about how to achieve forum topic search in ASP.NET AJAX. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "how to achieve forum theme search in ASP.NET AJAX". Next, please follow the editor to study!
One example we are going to see is a modification to an existing application. I * heard that the idea is that Josh Ledgard envisions adding a feature to the MSDN forum. The goal is to try to help users find answers to their own questions and to limit the number of repeated posts. Generally speaking, when a user asks a new question in the forum, he or she will enter the topic and question. They don't usually search first to see if the question has been asked and answered. Enter AJAX. After the user enters the topic (and moves the Tab key out of the field), we search the forum asynchronously based on the topic and display the results to the user at the right time. Sometimes these results help, sometimes they don't.
To make the results helpful, we will modify asp.NETPRO Reader's Choice Award for Best Forum Application, CommunityServer. The code for this section (or forum) is not included in the downloadable example, but you can learn more about CommunityServer in http://communityserver.org/ (English) and apply the following code snippets to it.
After installing CommunityServer and configuring Ajax.NET (references and handlers have been added to web.config), we only need to make a few changes to get the functionality we need. First, let's go to the CreateEditPost.cs file in the CommunityServerForums project. Think of it as the code later on this page, where the user can add a new publication. Next we will add a function with AJAX enabled.
/ / C#:ASP.NET AJAX example [Ajax.AjaxMethod ()] public static ArrayList Search (string search) {SearchQuery query = new SearchQuery (); query.PageIndex = 0; / / get the first 10 results query.PageSize = 10; query.UserID = Users.GetUser (). UserID; query.SearchTerms = search; return new ForumSearch (). GetSearchResults (query) .posts;}
We can take advantage of the search function that has been created in CommunityServer, as long as our function can apply it. As usual, types must be registered with Ajax.NET. We will do this in the InitializeSkin function of the same file (think of it as Page_Load).
/ / C#:ASP.NET AJAX sample Ajax.Utility.RegisterTypeForAjax (typeof (CreateEditPost))
Before we can jump to JavaScript, we need to make server-side changes. Custom classes that are returned to Ajax.NET (such as the ForumPost contained in the ArrayList we are returning) must be marked with the Serializable attribute. What we need to do is go to the Components/ForumPost.cs file in the CommunityServerForums project and add this property.
/ / C#:ASP.NET AJAX example [Serializable] public class ForumPost: Post {...}
When displayed, we only need to modify the Themes/default/Skins/View-EditCreatePost.cs in the CommunityServerWeb project. First, we will trigger the onBlur event of the topic text box.
< asp:textbox onBlur="Search(this.value);" id="PostSubject" runat="server" ... />Next, we write the JavaScript Search method to call the server-side Search.
Var oldValue ='; function Search (value) {/ / do not search the content you just searched again / / if the user moves the Tab key backward or forward, if (value! = oldValue) {CreateEditPost.Search (value, Search_CallBack); oldValue = value;}} will occur.
* *, all that's left is to process the response. Since the previous example showed a slightly more formal way to display the results in a table, we will just create some dynamic HTML and paste it into the virtual DIV.
Function Search_CallBack (response) {/ / because the search function will be automatically redirected when there are no results, / / therefore, we cannot use response.error. Var results = response.value; / / if we don't get the result if (results = = null) {return;} / / the DIV var someDiv = document.getElementById ("someDiv") we used to place the result; var html = ""; for (var I = 0; I)
< results.length; ++i) { var result = results[i]; html += "< a target=_blank href='" + result.PostID html += "/ShowPost.aspx'>"html + = result.Subject; html + ="
< /a> < br />"} someDiv [XSS _ clean] = html;}
By slightly modifying the three files of the CommunityServer application (plus the web.config for configuration), we can add some very useful functionality. However, be careful when you only add AJAX-enabled functionality to existing applications. The pre-existing ForumSearch classes that are actually searching may not have been designed for the usage types we introduced. Our code is likely to cause some additional searches to be performed, and the impact may be significant.
At this point, the study on "how to achieve forum topic search in ASP.NET AJAX" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.