Determine which update panel caused postback?
Suppose I have 3 update panels. How could I dete开发者_StackOverflowct which update panel caused a partial postback from JavaScript.
Use Hidden field
assign value before calling _dopostback() in javascript and by this on server you can specify that which updatepanel is postback.
I had a custom implementation of a web user control where I had a manager bound to the field, then I marked the input with an attribute so that I was able to find it easier If you find a way to know which updatePanels you had, then you'd be able to do it too
This is a simple example, and the reasons for it to work that way would be a very long explanation, but I wanted to leave it here in case someone finds it useful
It may have some bug, I am rushed to leave, perhaps I'll get to test it later on today
If you put this inside an update panel you should see it working
<span id="foo" customattr="foo_msg">click for foo_msg</span>
Finallu, what I did was something like this
<html>
<head>
//make sure this executes on load
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(myHandler);
function MyManager(message){
this.message=message;
this.notify=function(){alert(this.message);}
}
$(
function(){
$("[customattr=Y]").each(
function(){
this.objAttr=new MyManager($(this).attr("customattr"));
$.data(document.body,this.id,objAttr);
$(this).click(
function(){
this.objAttr.notify();
}
)
}
}
);
function myHandler(a,b){
$("[customattr]").each(
function(){
if(!this.objAttr){
//smells like postback regenerated this field
//let's get it back
this.objAttr=$.data(document.body,this.id);
}
}
);
}
</head>
<body>
<span id="foo" customattr="foo_msg">click for foo_msg</span>
<span id="bar" customattr="bar_msg">click for bar_msg</span>
</body>
<html>
精彩评论