Hi, Im using the code below to load an aspx page
.js file
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
function ajaxpage(url, containerid)
{
var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject)
{
try
{
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e)
{
try
{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e)
{
}
}
}
else
return false
page_request.onreadystatechange=function()
{
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}
function loadpage(page_request, containerid)
{
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
function loadobjs()
{
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++)
{
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1)
{
if (file.indexOf(".js")!=-1)
{
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1)
{
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!="")
{
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" "
}
}
}
and this code in .cs file
Working fine with this code loading simple pages. (just display Hello World!)
protected void AddORG_Click(object sender, EventArgs e)
{
Page.RegisterClientScriptBlock("ajax", "<script type='text/javascript'>ajaxpage('Main.aspx', 'pageContent')</script>");
}
but when I make the code like this (to store data in the sql). It display the error.
protected void AddORG_Click(object sender, EventArgs e)
{
Page.RegisterClientScriptBlock("ajax", "<script type='text/javascript'>ajaxpage('Main.aspx', 'pageContent')</script>");
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AccountConnectionString"].ConnectionString);
con.Open();
string cmdStr = "SELECT count(Org_Name) FROM Organization WHERE Org_Name='" + txtOrgName.Text + "'";
SqlCommand checkOrgExist = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt16(checkOrgExist.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
lblError.Visible = true;
lblError.Text = "Organization already exist, Please try another name.";
lblError.ForeColor = System.Drawing.Color.Red;
}
else
{
con.Open();
string addOrg = "INSERT INTO Organization(Org_Name, Org_Info, User_ID) VALUES(@Org_Name, @Org_Info, @User_ID)";
SqlCommand add = new SqlCommand(addOrg, con);
add.Parameters.AddWithValue("@Org_Name", txtOrgName.Text);
add.Parameters.AddWithValue("@Org_Info", txtOrgInfo.Text);
add.Parameters.AddWithValue("@User_ID", "12345");
try
{
add.ExecuteNonQuery();
con.Close();
lblError.Visible = true;
lblError.Text = "Successfully Created!";
lblError.ForeColor = System.Drawing.Color.GreenYellow;
}
catch (Exception er)
{
Response.Write(er);
}
}
}
ERROR MESSAGE:
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.
anyone can help me solve this problem?
Thanks in advance..