Edge浏览器中ASP.NET UpdatePanel内RadDatePicker回发JS报错求助
I've run into this exact issue before with the old EdgeHTML-based Edge (version 44.x) and Telerik's 2019.x RadControls in UpdatePanels. The error pops up because the partial postback from the UpdatePanel messes up the RadDatePicker's JavaScript initialization in this specific browser version. Here are several solutions you can try:
1. Upgrade Telerik RadControls (Recommended)
The most permanent fix is to upgrade your Telerik UI for ASP.NET AJAX version to a release that addresses old Edge compatibility issues. Telerik patched this specific problem in later versions (starting around 2019.3 or newer). Updating will not only resolve this error but also give you access to other bug fixes and improvements.
2. Reinitialize RadDatePicker After Partial Postbacks
If upgrading isn't an option right now, you can manually reinitialize the date picker after each UpdatePanel postback using the PageRequestManager's endRequest event. Add this script to your page (inside the <head> or at the end of <body>):
<script type="text/javascript"> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) { // Get the client-side instance of the RadDatePicker var datePicker = $find("<%= dpStartDate.ClientID %>"); // Check if the control exists and its popup button isn't initialized (sign of broken state) if (datePicker && !datePicker.get_popupButton()) { // Recreate the control's JavaScript components datePicker.recreate(); } }); </script>
This ensures that after every partial postback, the RadDatePicker's JS logic is properly reset, fixing the length property error.
3. Disable AutoPostBack on RadDatePicker
A quick workaround is to turn off the AutoPostBack property of the RadDatePicker. This prevents the immediate partial postback when a date is selected, and users can click the "Save" button to trigger the postback instead. Modify your RadDatePicker declaration:
<telerik:RadDatePicker ID="dpStartDate" runat="server" AutoPostBack="false" OnSelectedDateChanged="dpStartDate_SelectedDateChanged" />
This avoids the problematic postback scenario entirely, though it changes the user interaction slightly.
4. Browser-Specific Delay for Initialization
Old Edge sometimes needs a small delay before initializing controls after partial postbacks. You can add a browser check and delayed reinitialization:
<script type="text/javascript"> function isLegacyEdge() { // Detect old EdgeHTML-based Edge (not Chromium Edge) return navigator.userAgent.includes("Edge/") && !navigator.userAgent.includes("Edg/"); } Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(sender, args) { if (isLegacyEdge()) { var datePicker = $find("<%= dpStartDate.ClientID %>"); if (datePicker) { // Add a small delay to ensure DOM is ready setTimeout(function() { datePicker.recreate(); }, 100); } } }); </script>
Any of these approaches should resolve the JavaScript error you're seeing in old Edge. The upgrade path is the best long-term solution, but the reinitialization scripts work well as temporary fixes.
内容的提问来源于stack exchange,提问作者dov765

