使用jQuery将JSON数据装载到UpdatePanel触发器上
带有UpdatePanel和UserControl的VS2010页面。该页面是一个搜索工具,用于搜索大于10个条件的大型表。UpdatePanel接收搜索结果。UserControl是页面的新添加项 假设该页面查找拥有音乐CD的用户。以前,每个人都有一种与身份相关的类型,这是一种1-1关系。DB已经更新以支持多对多,因此UserControl在搜索时可以实现多种类型的选择 基本上,以前你只能发现人们喜欢重金属。你现在可以发现人们喜欢重金属和朋克还有 usercontrol将一个html表发送回页面,jQuery通过更改CSS类来响应keyup,这样,如果用户单击一个可见的选项,可能的选项就不可见、可见或固定 所以我有这个:使用jQuery将JSON数据装载到UpdatePanel触发器上,jquery,json,triggers,updatepanel,partial-postback,Jquery,Json,Triggers,Updatepanel,Partial Postback,带有UpdatePanel和UserControl的VS2010页面。该页面是一个搜索工具,用于搜索大于10个条件的大型表。UpdatePanel接收搜索结果。UserControl是页面的新添加项 假设该页面查找拥有音乐CD的用户。以前,每个人都有一种与身份相关的类型,这是一种1-1关系。DB已经更新以支持多对多,因此UserControl在搜索时可以实现多种类型的选择 基本上,以前你只能发现人们喜欢重金属。你现在可以发现人们喜欢重金属和朋克还有 usercontrol将一个html表发送回页
<tr class='genre_hidden'><td>Jazz-Bebop</td></tr>
<tr class='genre_hidden'><td>Jazz-Trad</td></tr>
<tr class='genre_hidden'><td>Jazz-Dixie</td></tr>
<tr class='genre_pinned'><td>Punk</td></tr>
<tr class='genre_pinned'><td>Heavy Metal</td></tr>
<tr class='genre_visible'><td>Classic Rock</td></tr>
我有没有违反规则/有没有更好的办法?好吧,看来我得回答我自己的问题了。如果你想像我一样做,这里是人们需要的片段 希望它能帮助别人 干杯, 警察局 在用户控件所在的页面中,需要捕获提交updatepanel的单击
<script type="text/javascript">
$(subscribeClicks);
// for use on pages with updatepanels. once the panel has reloaded, the jquery
// events get slagged so we need to rebind them here.
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(subscribeClicks);
function subscribeClicks() {
// catch the search button before it (partially) posts back and send
// data
$('input[id*="btnSearch"]').click(function (e) {
// this function is in a script in your usercontrol
senddataFromUserControl('ThisPage.aspx/NameOfYourWebMethod');
});
}
</script>
在C中:
public class SearchArgs {
public string Name;
public string Value;
}
object o = yourUserControl.FindControl("hdnSessionKey");
HtmlInputHidden hdn = (HtmlInputHidden)o;
if (hdn != null) {
string key = hdn.Value;
List<SearchArgs> filterValues = List<SearchArgs>)Session[key];
foreach (SearchArgs filterValue in filterValues) {
// do what you need to prep this for your data layer
}
Session[key] = null;
}
然后首先用VB编写webmethod
<System.Web.Services.WebMethod()> _
Public Shared Function NameOfYourWebMethod(args As List(Of SearchArgs)) As String
' generate a session key for the client to pass back when the page postback occurs
Dim key As String = String.Format("IDT_{0:yyMMddhhmmss}", Now)
HttpContext.Current.Session(key) = args
Return key
End Function
在C中:
public class SearchArgs {
public string Name;
public string Value;
}
object o = yourUserControl.FindControl("hdnSessionKey");
HtmlInputHidden hdn = (HtmlInputHidden)o;
if (hdn != null) {
string key = hdn.Value;
List<SearchArgs> filterValues = List<SearchArgs>)Session[key];
foreach (SearchArgs filterValue in filterValues) {
// do what you need to prep this for your data layer
}
Session[key] = null;
}
选择您想要的,从中提取值,然后发送它们。。。你到底试过什么?给我们一个您自己如何解决这个问题的示例,可以帮助我们更好地理解您试图实现的目标。您的ajax请求是否设置为async:false?否则,在ajax完成和隐藏输入更新之前,普通按钮处理程序将返回true。这解释了为什么它只有在我遍历它时才起作用,但没有断点:谢谢。这是我建议使用async:false的极少数情况之一。
[System.Web.Services.WebMethod()]
public static string NameOfYourWebMethod(List<SearchArgs> args)
{
// generate a session key for the client to pass back when the page postback occurs
string key = string.Format("IDT_{0:yyMMddhhmmss}", DateAndTime.Now);
HttpContext.Current.Session[key] = args;
return key;
}
Dim o As Object = yourUserControl.FindControl("hdnSessionKey")
Dim hdn As HtmlInputHidden = CType(o, HtmlInputHidden)
If hdn IsNot Nothing Then
Dim key As String = hdn.Value
Dim filterValues As List(Of SearchArgs) = CType(Session(key), List(Of SearchArgs))
For Each filterValue As SearchArgs In filterValues
' do what you need to prep this for your data layer
Next
Session(key) = Nothing
End If
object o = yourUserControl.FindControl("hdnSessionKey");
HtmlInputHidden hdn = (HtmlInputHidden)o;
if (hdn != null) {
string key = hdn.Value;
List<SearchArgs> filterValues = List<SearchArgs>)Session[key];
foreach (SearchArgs filterValue in filterValues) {
// do what you need to prep this for your data layer
}
Session[key] = null;
}