Solved

How do I use Ajaxpro to update a database from the client?

Posted on 2009-04-12
5
453 Views
Last Modified: 2012-05-06
I hope someone can help me as I'm close to ripping my hair out.
I wrote a web application using vs 2005 and vb.net.  All I want is to display a message box on the client asking the user to confirm record deletions.  If they select yes, I want to run some server side code.
I discovered the bext way of doing this is to use the AJAXpro dll and mark my server side code with an ajaxmethod attribute. Unfortunately when I started this project I wasnt familiar with C# so I used vb.net and i cant find any examples of this with vb.net.
Originally it was a web site.  It would call the function from but return a null value.  I found this to be caused by the vb.net namespace problem.  There was no way of specifying a root namespace so i had a choice of converting to a web application or rewrting the code in C#. (it works perfectly in C#)
I imported it into a new web application, set up the references and built the code.  Now it wont call the function from javascript at all.  It just says 'object not found' even though the function exists and is spelt correctly.  It resides in the aspx page, in script tags inside <head>.
I would like to ask if I have to do anything specifically to enable java script in a web application, that i dont have to do in a web site?  Or is there a less complicated way of acheiving my end goal?

Thanks in advance.
0
Comment
Question by:Terry907
  • 3
5 Comments
 
LVL 3

Expert Comment

by:OutOfTouch
ID: 24133512
Please post some code?
Javascript and the PageMethod being called would help.
Thanks.
0
 

Author Comment

by:Terry907
ID: 24136503
No javascript functionality at all seems to be working.  I commented out the line in the function that calls the ajaxmethod and the line in my page_load event that registers they type and it still doesnt work.  Once I get javascript to work I can then concentrate on my bigger problem.

I have done a lot of work with server side technologies and I actually have 3 MCAD certifications but this is the first time I have looked at client side code.  It just seems to throw up fresh problem after fresh problem.  Maybe there is something obvious i am missing?
I put this in my page_load event:
 LinkButton2.Attributes.Add("Onclick", "update();")
 
I commented out the line that runs the ajaxmethod to see if it had an effect but it still causes an error.
Function update()
    {
    alert("hello");
  // LocalInformationvb1.Contacts.UpdateRecord(UpdateCallback)
    }
 
 
This is the HTML it generates.
 
<a onclick="update();" id="LinkButton2" href="javascript:__doPostBack('LinkButton2','')" style="z-index: 139; left: 0px; position: absolute;
            top: 0px">LinkButton</a>
 
This is the error:
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code
Microsoft JScript runtime error: Object expected

Open in new window

0
 
LVL 3

Accepted Solution

by:
OutOfTouch earned 500 total points
ID: 24141598
Can you post your server side method declaration of UpdateRecord, just the attributes applied to it would be fine along with the declaration line, I don't need to see the whole method.
The link button by default works like a submit button, I think the fact that the button wants to doPostBack is part of your problem.
Here is what I think your saying you want to do:
User clicks a button that calls JavaScript to ask the user if they want to delete the record, return true or false, if false than stop the form submit, if true than postback? Or are trying to do a partial postback when they decide to delete the record?
To call a page method  you  must declare the method as Static and it must be marked with the <WebMethod> attribute, you also need to use PageMethod.UpdateRecord in the JavaScript.
 Here is a simple example :
http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
Also instead of an alert box you probably want to use a confirm box :
http://www.w3schools.com/JS/js_popup.asp
http://www.w3schools.com/JS/tryit.asp?filename=tryjs_confirm

 
0
 
LVL 3

Expert Comment

by:OutOfTouch
ID: 24146988
PageMethod above should be PageMethods sorry for the typo.
Here is some more info :
http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx
 
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complex SQL statement in VB.NET 7 31
Generate Unique ID in VB.NET 21 67
Please explain purpose of GZIP 4 37
ASP.NET MVC - Views 3 22
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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