Cannot access DevExpress ASP.NET MVC extensions on the client
- 2 minutes to read
Error Description:
This error occurs when you try to use the following methods/events:
The ClientScriptManager.RegisterStartupScript method.
The window.onload event.
The $(document).ready() jQuery function.
Solution:
This error occurs because DevExpress ASP.NET MVC extensions are not completely initialized on the client when you call the startup script, window.onload or document.ready. We do not recommended that you use these APIs with our extensions on the client while other extensions are still active. These approaches are not reliable and can lead to invalid access to extensions on the client.
Use any of the following solutions to resolve the issue:
Handle the client-side Init event to initialize the extension on the client when a page loads.
@Html.DevExpress().TextBox(settings => { settings.Name = "TextBox"; settings.Properties.ClientSideEvents.Init = "OnTextBoxInit"; });
@Html.DevExpress().TextBox( Sub(settings) settings.Name = "TextBox" settings.Properties.ClientSideEvents.Init = "OnTextBoxInit" End Sub).GetHtml()
function OnTextBoxInit(s, e) { s.SetText('...'); }
Handle the ControlsInitialized event to make sure that all DevExpress ASP.NET MVC extensions are initialized and accessible on the client.
@Html.DevExpress().TextBox(settings => { settings.Name = "TextBox"; }).GetHtml()
@Html.DevExpress().TextBox( Sub(settings) settings.Name = "TextBox" End Sub).GetHtml()
MVCxClientGlobalEvents.AddControlsInitializedEventHandler(function () { TextBox.SetText('...'); });
Note
The ControlsInitialized event is raised each time DevExpress ASP.NET MVC extensions send a request to the server. You can use the constructor(isCallback) parameter to determine if an event is raised as a result of a DevExpress callback.
function OnControlsInitialized(s, e) { if(!e.isCallback) // Changes the editor's text on the first load only TextBox.SetText('...'); }
See Also: