Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
XML
<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>
        &nbsp;<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]
Posted
Updated 30-Apr-11 4:55am
v2

1 solution

 
Share this answer
 
Comments
hesamsaleh 30-Apr-11 13:09pm    
thanks for youre attention...
befor posting this topic i try both of this example but this solution's dont help me to solved my problme..
thanks Again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900