JQuery和ASP.NET Web表单 [英] JQuery and ASP.NET Web Forms

查看:99
本文介绍了JQuery和ASP.NET Web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个ASP.NET Web窗体应用程序,试图在其中使用一些不错的jQuery功能和浮华度.我拥有的应用程序的当前部分由两个jQuery UI选项卡组成.搜索标签和结果标签.当用户从搜索页​​面执行搜索时,将选择结果"选项卡,并且结果将显示在此选项卡中.我需要将结果放入gridview.现在这是问题开始出现的地方:

I am creating a ASP.NET Web Form application where I am trying to use some nice jQuery functionality and flashyness. The current part of the application I have consists of two jQuery UI tabs; a search tab and a results tab. When the user performs a search from the search page, the results tab will be selected and the results will be displayed in this tab. I need to get the results into a gridview. Now this is where the issue starts to come in:

获得搜索结果的最简单方法是允许搜索单击执行回发,然后我可以使用输入字段中的参数来格式化数据源,并让datagrid自行处理并绑定数据并显示结果.事实是,这看起来似乎并不那么好(由于整个回发之类),并且由于使用回发重新初始化了所有内容,因此开始使用javascript/jQuery引起选项卡切换以及所有这部分问题来自jQuery UI(即jQuery UI选项卡).因此,简而言之,回发可以轻松绑定输入以进行搜索并获得结果,但使页面及其行为都变得很奇怪.

The easiest way to get the search results is to allow the search click to perform the postback where I can then format the datasource with the parameters from the input fields and let the datagrid take care of itself and data bind and show the results. The thing is, this really doesn't look that great (due to the whole post back and such) as well as starts to cause some issues with using javascript/jQuery to take care of tab switching and all that portion because the postback reinitializes everything from the jQuery UI (i.e. the jQuery UI tabs). So in short, the postback allows for easy binding of the input for the search and getting the results, but makes the page and its behavior all wonky.

我想知道是否存在一种标准方法来在Web表单中将jQuery/javascript/AJAX混合在一起以获取诸如gridview之类的功能.我想知道是否有一些好的教程,或者仅仅是解决这个问题的指导.

I was wondering if there is a standard way to do this type of mixing jQuery/javascript/AJAX all together within web formto get the functionality of things like the gridview and such. I am wondering if there are some good tutorials, or even just a direction on solving this issue.

我希望所有这些都有意义,并感谢大家的帮助.

I hope all this made sense, and thank you all for your help.

推荐答案

我不认为这是一个标准,但这是我使用的模式:

I don't think this is a standard, but here is the pattern I use:

首先,我使用 ASP.Net的页面方法将其连接到服务器.在这种情况下,将是这样的:

First of all, I use Page Methods for ASP.Net to get hooked back up to the server. In this case it would be something like this:

PageMethods.Search(searchValue, onSearchComplete);

这将在页面中调用静态页面方法,如下所示:

That calls a static page method in the page, like this:

public static void Search(string searchValue)
...

在该过程中,我创建一个包含Gridview的用户控件的实例,并在该控件上调用一个方法,并传递searchValue:

Inside that procedure, I create an instance of a user control which contains the gridview, and invoke a method on that control, passing the searchValue:

var searchControl = (SearchControl)new SearchControl().LoadControl("/controls/SearchControl.ascx");

searchControl.Search();

var stringBuilder = new StringBuilder();
using (var textWriter = new StringWriter(stringBuilder))
{
      var htmlWriter = new HtmlTextWriter(textWriter);

      searchControl.RenderControl(htmlWriter);
      return stringBuilder.ToString();
}

在本示例中,所有这些最终将作为您在初始调用(onSearchComplete)中指定的处理程序的结果参数.您可以对标记进行任何操作,包括将其打入div或提醒其进行调试.

This is all going to end up as the result argument to the handler you specified in the initial call (onSearchComplete) in this example. You can do whatever you want with the markup, including slapping it into a div, or alerting it for debugging.

这篇关于JQuery和ASP.NET Web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆