Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Custom ajax control does not work after uppgrading from 4.1.60919 to 7.1213.0

$
0
0

I have a custom ajax control that i use for printing content on a html page.

But after uppgrading the version of asp.net i get the following error

JavaScript runtime error: Sys.ArgumentUndefinedException: Value cannot be undefined.
Parameter name: type

you can find a example here (one with 4.1.60919 and one with 7.1213.0)

http://www.sendspace.com/filegroup/vJn9TXtcFA1KMpq6xM24lg

PrintButtonExtender.vb

Imports System.ComponentModel
Imports AjaxControlToolkit
Imports System.Web.UI
Imports System.Web.UI.WebControls<Assembly: WebResource("CustomAjax.Extenders.PrintButtonBehavior.js", "text/javascript")> <Assembly: WebResource("CustomAjax.Extenders.PrintButtonBehavior.debug.js", "text/javascript")> <Designer(GetType(PrintButtonExtenderDesigner))><ClientScriptResource("Sys.Extended.UI.PrintButtonExtender", LoadOrder:=0, ResourcePath:="CustomAjax.Extenders.PrintButtonBehavior.js")><TargetControlType(GetType(IButtonControl))> _
Public Class PrintButtonExtender
    Inherits ExtenderControlBase

    ''' <summary>
    ''' Control that has the content to print
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks><ExtenderControlProperty()><DefaultValue(CStr(Nothing))><IDReferenceProperty(GetType(Control))>
    Public Property PrintControlID As String
        Get
            Return CStr(ViewState("PrintControlID"))
        End Get
        Set(value As String)
            ViewState("PrintControlID") = value
        End Set
    End Property

    ''' <summary>
    ''' Extra css to apply to the printed content.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks><ExtenderControlProperty()><DefaultValue(CStr(Nothing))>
    Public Property PrintingCss As String
        Get
            Return GetPropertyValue(Of String)("PrintingCss", Nothing)
        End Get
        Set(value As String)
            SetPropertyValue(Of String)("PrintingCss", value)
        End Set
    End Property<ExtenderControlProperty()><DefaultValue(600)>
    Public Property PrintingWindowHeight As Integer
        Get
            Return GetPropertyValue(Of Integer)("PrintingWindowHeight", 600)
        End Get
        Set(value As Integer)
            SetPropertyValue(Of Integer)("PrintingWindowHeight", value)
        End Set
    End Property<ExtenderControlProperty()><DefaultValue(600)>
    Public Property PrintingWindowWidth As Integer
        Get
            Return GetPropertyValue(Of Integer)("PrintingWindowWidth", 600)
        End Get
        Set(value As Integer)
            SetPropertyValue(Of Integer)("PrintingWindowWidth", value)
        End Set
    End Property<ExtenderControlProperty()><DefaultValue(CStr(Nothing))>
    Public Property PrintingWindowTitle As String
        Get

            Return GetPropertyValue(Of String)("PrintingWindowTitle", Nothing)
        End Get
        Set(value As String)
            SetPropertyValue(Of String)("PrintingWindowTitle", value)
        End Set
    End Property

    Private Sub PrintButtonExtender_Init(sender As Object, e As System.EventArgs) Handles Me.Init
        If (Not String.IsNullOrEmpty(PrintControlID)) Then
            Dim control As Control = Me.Parent.FindControl(PrintControlID)
            If (control IsNot Nothing) Then
                SetPropertyValue(Of String)("PrintControlID", control.ClientID)
            End If
        End If
    End Sub
End Class

PrintButtonBehavior.debug.js

Type.registerNamespace('Sys.Extended.UI');
Sys.Extended.UI.PrintButtonExtender = function (element) {
    Sys.Extended.UI.PrintButtonExtender.initializeBase(this, [element]);
    this._printControlIDValue = null;
    this._printingCssValue = null;
    this._printingWindowHeightValue = 600;
    this._printingWindowWidthValue = 600;
    this._printingWindowTitleValue = null;

    this._PrintElement = function () {
        var extraCss = this._printingCssValue;
        var element = document.getElementById(this._printControlIDValue);
        var width = this._printingWindowWidthValue;
        var height = this._printingWindowHeightValue;
        var title = this._printingWindowTitleValue;
        var documentStyles = this._GetDocumentStyles();
        if (title == null)
            title = "";
        //Open new window
        var win = window.open("", title, "width=" + width + "px,height=" + height + "px,status=1,resizable=1,toolbar=1,menubar=1");
        win.document.open();

        win.document.write("<html><head><title>" + title + "</title>");

        win.document.write(documentStyles);

        //Apply extra css
        if (extraCss !== undefined && extraCss !== null) {
            win.document.write("<style type=\"text/css\">" + extraCss + "</style>");
        }
        win.document.write("</head><body>" + this._OuterHTML(element) + "</body></html>");
        win.document.close();

        //Print window after a 250 ms delay
        setTimeout(function () {
            win.print();
            //win.close();
        }, 250);
        return false;
    };

    this._OuterHTML = function (node) {
        // if IE, Chrome take the internal method otherwise build one
        return node.outerHTML || (
            function(n){
                var div = document.createElement('div'), h;
                div.appendChild( n.cloneNode(true) );
                h = div.innerHTML;
                div = null;
                return h;
            })(node);
    };

    this._GetDocumentStyles = function () {
        var header = document.getElementsByTagName("HEAD")[0];
        var result = "";
        var styles = header.getElementsByTagName("style");
        for (var i = 0; i < styles.length; i++) {
            result += this._OuterHTML(styles[i]) + "\n";
        }
        var links = header.getElementsByTagName("link");
        for (var i = 0; i < links.length; i++) {
            result += this._OuterHTML(links[i]) + "\n";
        }
        return result;
    };
}


Sys.Extended.UI.PrintButtonExtender.prototype = {
    initialize: function () {
        Sys.Extended.UI.PrintButtonExtender.callBaseMethod(this, 'initialize');
        var element = this.get_element();
        this._clickHandler = Function.createDelegate(this, this._clickCallback);
        $addHandler(element, "click", this._clickHandler);
        element.setAttribute("onclick", null);
    },

    dispose: function () {

        this._printControlIdValue = null;
        this._printingCssValue = null;

        $removeHandler(this.get_element(), "click", this._clickHandler);
        this._clickHandler = null;


        Sys.Extended.UI.PrintButtonExtender.callBaseMethod(this, 'dispose');
    },

    _clickCallback: function (e) {
        e.preventDefault();
        this._PrintElement();
        return false;
    },

    get_PrintControlID: function () {
        return this._printControlIDValue;
    },
    set_PrintControlID: function (value) {
        this._printControlIDValue = value;
    },

    get_PrintingCss: function () {
        return this._printingCssValue;
    },
    set_PrintingCss: function (value) {
        this._printingCssValue = value;
    },

    get_PrintingWindowHeight: function () {
        return this._printingWindowHeightValue;
    },
    set_PrintingWindowHeight: function (value) {
        this._printingWindowHeightValue = value;
    },

    get_PrintingWindowWidth: function () {
        return this._printingWindowWidthValue;
    },
    set_PrintingWindowWidth: function (value) {
        this._printingWindowWidthValue = value;
    },

    get_PrintingWindowTitle: function () {
        return this._printingWindowTitleValue;
    },
    set_PrintingWindowTitle: function (value) {
        this._printingWindowTitleValue = value;
    }
}

Sys.Extended.UI.PrintButtonExtender.registerClass('Sys.Extended.UI.PrintButtonExtender', Sys.Extended.UI.BehaviorBase);

Edit:

After adding AjaxControlToolkit.config i instead get 

Value cannot be null.
Parameter name: key 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: key

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[ArgumentNullException: Value cannot be null.
Parameter name: key]
   System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +10627293
   System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) +12
   AjaxControlToolkit.ScriptObjectBuilder.GetScriptReferencesInternal(Type type, Stack`1 typeReferenceStack, Boolean ignoreStartingTypeReferences) +282
   AjaxControlToolkit.ScriptObjectBuilder.GetScriptReferences(Type type, Boolean ignoreStartingTypeReferences) +79
   AjaxControlToolkit.ScriptObjectBuilder.GetScriptReferences(Type type) +38
   AjaxControlToolkit.ToolkitScriptManagerConfig.GetScriptReferences(HttpContextBase context, String[] bundles, ScriptReference[]& addedScriptReferences, ScriptReference[]& removedScriptReferences) +284
   AjaxControlToolkit.ToolkitScriptManagerCombiner.LoadScriptReferences(HttpContextBase context, String[] bundles) +82
   AjaxControlToolkit.ToolkitScriptManager.LoadScriptReferences(HttpContextBase context, String[] bundles, Boolean forCombineAndMinify) +159
   AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e) +340
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Control.LoadRecursive() +145
   System.Web.UI.Control.LoadRecursive() +145
   System.Web.UI.Control.LoadRecursive() +145
   System.Web.UI.Control.LoadRecursive() +145
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>