Hi...
on the below code i want to load my User Control Inside Div Tag Without Refresh..
I'm using A webService to do this action... everything is well but when i place a button on UserControl i have got this error "The state information is invalid for this page and might be corrupted" ... i'm search about So many people gave a solution that was set <page enableviewstate="false"> but that is not working for me...
Give me a recemmended for solving my broblme .
here is my code
on aspx page Source :
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head" runat="server">
<title>Test Application</title>
<style type="text/css">
body
{
width:95%;
padding-left:20px;
font-family:Arial;
font-size:10pt;
padding-right:20px;
}
.loading {
position:fixed;
bottom:20px;
left:20px;
float:right;
width:190px;
padding:15px 0 6px 0;
text-align:center;
font-size:9px;
color:#fff;
background:#003168 url(../load.jpg) center top no-repeat;
border:1px solid #fff;
font:11px tahoma;
display:none;
direction:rtl;
}
.loading img{
margin-bottom:2px;
}
</style>
</head>
<body>
<form id="form" runat="server">
<h5></h5>
<asp:ScriptManager runat="server">
<Services>
<asp:ServiceReference Path="~/ScriptService.asmx" />
</Services>
</asp:ScriptManager>
<input type="button" value="Load Login" onclick="getData('~/Controls/LoginControl.ascx');" />
<asp:Image Style ="visibility:hidden" ID="Image1" runat="server" ImageUrl="load.gif" />
<div id="testDiv"></div>
<div id="LoadingPanel" class="loading">
<span>
<img src="load.gif" />
<div>.wait for loading</div>
</span>
</div>
</form>
<script type="text/javascript">
function onFailedWS(error)
{
alert(error.get_message());
document.getElementById("LoadingPanel").style.display = "none";
}
function SucceededCallback(result) {
document.getElementById("LoadingPanel").style.display = "none";
var RsltElem = $get("testDiv");
RsltElem.innerHTML =result;
}
function getData(controlLocation) {
document.getElementById("LoadingPanel").style.display = "block";
ScriptService.GetControlHtml(controlLocation, SucceededCallback, onFailedWS);
}
</script>
</body>
</html>
On WebService :
using System;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class ScriptService : System.Web.Services.WebService
{
public ScriptService()
{
}
[WebMethod(EnableSession = true)]
public string GetControlHtml(string controlLocation)
{
Page page = new Page();
UserControl userControl = (UserControl)page.LoadControl(controlLocation);
HtmlForm form = new HtmlForm();
form.Controls.Add(userControl);
page.Controls.Add(form);
StringWriter textWriter = new StringWriter();
HttpContext.Current.Server.Execute(page, textWriter, false);
return CleanHtml(textWriter.ToString());
}
private string CleanHtml(string html)
{
return Regex.Replace(html, @"<[/]?(form|[ovwxp]:\w+)[^>]*?>", "", RegexOptions.IgnoreCase);
}
}
Help Me About That.. sorry about my bad English
[edit]Inline code changed to code block - OriginalGriff [/edit]