I've been looking everywhere for a solution to the static ClientIDMode + UpdatePanel in Asp.NET, as seen in http://connect.microsoft.com/VisualStudio/feedback/details/584991/clientidmode-static-in-updatepanel-fails-to-do-async-postback
The problem is in the Sys.WebForms.PageRequestManager.uniqueIDToClientID function, that converts names to id by replacing "$" characters to "". I made a fix that seems to work but I want you guys to tell me what you think and if I'm missing something. Thanks a lot!
var old_uniqueIDToClientID = Sys.WebForms.PageRequestManager.prototype._uniqueIDToClientID;
Sys.WebForms.PageRequestManager.prototype._uniqueIDToClientID = function (arg) {
var element = this._form.elements[arg];
return (element) ? element.id : old_uniqueIDToClientID(arg)
}
We made a similar fix, but we changed another function that was involved in the search for the element that caused the postback.
We have placed the following code at the bottom of our master page to make sure that it is included after the scriptmanager has loaded its scripts. Essentially it keeps modifying the id until it finds the element that caused the postback. The original code searched for the element by removing tokens from the right hand side of the name delimited by the dollar sign. So "$ctl00$ddl001" would become "$ctl00". If you are using static ids then that suffix might never exist. We modified the function to start from the left and remove the container names until an element is found.
It seems to work for us for now. :)
if (Sys.WebForms.PageRequestManager) {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._findNearestElement = function (uniqueID) {
while (uniqueID.length > 0) {
var clientID = this._uniqueIDToClientID(uniqueID);
var element = document.getElementById(clientID);
if (element) {
return element;
}
var indexOfFirstDollar = uniqueID.indexOf('$', 1);
if (indexOfFirstDollar === -1) {
return null;
}
uniqueID = uniqueID.substring(indexOfFirstDollar + 1, uniqueID.length);
}
return null;
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With