Solved

How to avoid javascript error 'args is not defined' in ajax autosave implementation?

Posted on 2011-09-13
6
625 Views
Last Modified: 2012-05-12
I have attempted to implement autosave on a .net application using an ajax update panel. I am having difficulty with preventing / capturing errors. My initial attempt to capture errors involved that addition of  including  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
I then coded the error capture withing the endRequest function. That resulted in a Sys is not defined error. I found this posting: http://encosia.com/updated-your-webconfig-but-sys-is-still-undefined/ which led me to my latest implementation which has the sys handling in a separate script file. Now I receive the error 'args is not defined'. I'm not sure how to reference the args  to enable the ajax call. So you can see I am now out of my depth. I have included the code from my .aspx file and js file below. Your help greatly appreciated
Verdy SysInstance.js
.aspx page
SCRIPT REFERENCE:
	<asp:ScriptManager ID="SMan" runat="server" >
	<Scripts>
		<asp:ScriptReference Path="js/SysInstance.js" />
	</Scripts>
</asp:ScriptManager>

UPDATEPANEL CONTROL:
	    <asp:UpdatePanel ID="Deneme" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerAutoSave" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:HiddenField ID="hdnUserID" runat="server" Value="" />
            <asp:HiddenField ID="hdnLanguageCode" runat="server" Value="" />
            <asp:HiddenField ID="hdnTempDocID" runat="server" Value="" />
            <asp:HiddenField ID="hdnServerName" runat="server" Value="" />
            <asp:HiddenField ID="hdnServerPort" runat="server" Value="" />
            <asp:HiddenField ID="hdnVirtualDirectoryName" runat="server" Value="" />
            <asp:HiddenField ID="hdnPostASPX" runat="server" Value="" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Timer ID="TimerAutoSave" runat="server" Interval="5000" OnTick="TimerAutoSave_Tick">
    </asp:Timer>

Open in new window

0
Comment
Question by:verdante
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 36533434
check if this solves your problem

Sys.Application.add_init(AppInit);

function AppInit() {
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
}

function beginRequest(sender,args) {
    if (args.get_error() != undefined) {
        //$get('Error').style.visibility = "visible"; // Let the framework know that the error is handled, // so it doesn't throw the JavaScript alert.
        $get('Error').style.visibility = "hidden"; // Let the framework know that the error is handled, // so it doesn't throw the JavaScript alert.
        args.set_errorHandled(true);
    }
    prm._scrollPosition = null;
}

function endRequest(sender, args) { // Check to see if there's an error on this request.
    if (args.get_error() != undefined)
    //if ($get('Error').style.visibility == "visible")
    //    CloseError();
    {
        $get('Error').style.visibility = "hidden"; // Let the framework know that the error is handled, // so it doesn't throw the JavaScript alert.
        args.set_errorHandled(true);
    }
}
0
 

Author Comment

by:verdante
ID: 36533516
Thanks SriVaddadi. I get a new error now:

args.get_error is not a function

cheers

Verdy
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 36533643
BeginRequestEventArgs does not have have get_error method. you have remove the code referring get_error in beginRequest

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:verdante
ID: 36533882
Thanks. Sorry this is my code when I remove the comments. I thought the get_error() method was a property of the args parameter. Can you please advise how I can modify this code to make sure the get_error method is included:

function beginRequest(sender, args) {
    if (args.get_error() != undefined) {
        $get('Error').style.visibility = "hidden";
        args.set_errorHandled(true);
    }
    prm._scrollPosition = null;
}


0
 
LVL 16

Accepted Solution

by:
SriVaddadi earned 500 total points
ID: 36536076
Check here for better understanding
http://msdn.microsoft.com/en-us/library/bb383922.aspx

Not sure what you are intending to do but the BeginRequestEventArgs does not give you error object but EndRequestEventArgs does.

It makes sense because you would not have any error for that request even before sending request

You could have the code in endRequest handler. what kind of error info you are looking for?
0
 

Author Closing Comment

by:verdante
ID: 36536388
Thx for that. AS you can see I am out of my depth but you have taught me well. I removed the error handling from the beginrequest and it works nicely.
I'll also check out the link so I have a better understanding

thx again
Verdy
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML5 frame 5 25
Best Way to remove the port from a URL? 15 36
How can i  prevent default  Submision? 6 27
Html form and modal / img src -problem 3 10
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question