|
-
Sep 25th, 2012, 11:48 AM
#1
Thread Starter
Member
asp.net with xmlhttprequest
Hi all,
I've been trying to write a web page in asp.net which uses a javascript xmlhttprequest object to return the contents of another asp.net page when the user clicks a button.
Having spent ages debugging the "unknown runtime error" that the browser throws, I've narrowed it down to the fact that the aspx page being accessed by the xmlhttprequest contains the standard asp.net <form id="form1" runat="server"> markup. If I change this to a <div> tag, the browser returns no error.
Does this mean that the xmlhttprequest object will not ever work with asp.net pages with a code behind file? I would have expected the xmlhttprequest to return the finished html generated by the aspx/VB server side code, as happens when you point xmlhttprequest at a PHP page, so not be affected by any pre-processing markup.
Can anyone explain, or tell me if there's a workaround?
Thank you.
-
Sep 25th, 2012, 07:11 PM
#2
Re: asp.net with xmlhttprequest
Having the asp <form tag on the page will cause .net to render markup that enables asp.net postbacks etc. If you want to use a aspx page for ajax requests you should employ "webMethods" see this link.
http://geekswithblogs.net/frankw/arc...spx-pages.aspx
You can also use a ashx handler page, you'll find it called "generic handler" when creating a new page. They have only a code page no design page.
http://www.developerfusion.com/code/...-an-ashx-file/
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
-
Oct 5th, 2012, 11:15 AM
#3
Thread Starter
Member
Re: asp.net with xmlhttprequest
Just in case anyone's interested, I discovered that, if you just need to use the back-end aspx page (i.e. the second aspx page in my example above) to render results which will be fed into your front page through AJAX, you can take out the <form runat="server"> tags from the second page and just have the page body run at the server. This allowed me to use a second aspx page to simply feed a table into my primary aspx page.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|