PDA

View Full Version : AjaxContent in ASP



nielcleo
06-02-2013, 06:27 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem:
I've been using the dynamic ajax content in my aspx project and its work well in simple pages with the use of buttons in asp by using this code in .cs


protected void Button1_Click(object sender, EventArgs e)
{
Page.RegisterClientScriptBlock("ajax", "<script type='text/javascript'>ajaxpage('New.aspx', 'content')</script>");
}


but now when I add sqlcommands to that button to add data in the database I always got an error.
and here's the error
Server Error in '/WebSite' Application.
The state information is invalid for this page and might be corrupted.
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.Web.HttpException: The state information is invalid for this page and might be corrupted.

i want to execute the sqlcommand and an laod the result in same div content.

please help me. Thanks in advance!

jscheuer1
06-16-2013, 08:24 AM
The ajaxpage function performs a GET request with no headers. Aside from any syntax errors you may or may not have in the code - you haven't shown the exact code that gives that error, you might need to be sending a POST or other type of request which requires a header.

I'm not real familiar with asp, I use PHP and am not expert at it either. But what I would do is make up a separate asp page that, if viewed in the browser, would show the content that you want to have appear in the target div and/or do anything else server side you want done. Use ajaxpage to fetch that page. That separate page cannot have any client side javascript on it though.

Like in PHP, I would put:


<?php echo 'Hello World'; ?>

or whatever, even much more complex PHP code like to write to/read from a file or database, on a separate page, say call it - hello.php, then use ajaxpage to fetch that:


ajaxpage('hello.php', 'content');