2009-06-10 4 views
0

Dans mon formulaire asp.net, j'actualise un contrôle en utilisant Ajax via la bibliothèque AjaxPro. Cependant, après l'avoir fait ... causant aucun résultat postback « normal » dans un écran jaune (erreur complète après le message)Informations d'état corrompues après l'ajout dynamique du contrôle

J'ai défini les propriétés suivantes dans la page web.config sans chance

<pages enableSessionState="true" enableViewState="false" enableEventValidation="false" enableViewStateMac="false"> 

J'ai également essayé de générer une clé machine comme certaines solutions proposées en ligne. Mais cela n'aide pas non plus.

Des suggestions? Contenu de l'écran jaune ASP .NET ******************** ****************

Server Error in '/' 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. 

Source Error: 

[No relevant source lines] 


Source File: c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\c89baa89\d92b83c5\App_Web_tahnujzf.4.cs Line: 0 

Stack Trace: 

[FormatException: Invalid character in a Base-64 string.] 
    System.Convert.FromBase64String(String s) +0 
    System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +72 
    System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4 
    System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37 
    System.Web.UI.HiddenFieldPageStatePersister.Load() +113 

[ViewStateException: Invalid viewstate. 
    Client IP: 127.0.0.1 
    Port: 49736 
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729) 
    ViewState: /wEPDwULLTE0OTczNDQ1NjdkGAIFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYGBSljdGwwMCR1c3JTaG9wcGluZ0xpc3QkdXNyU2hvcHBpbmdMaXN0X3duZAUaY3RsMDAkdXNyU2hvcHBpbmdMaXN0JF9tZ3IFVGN0bDAwJFBsYWNlSG9sZGVyTWFpbiRjdGwwMCRfJHVzclZpZXdDYXJ0Q29udHJvbCRfJGN0bDAwJF8kcnB0TGluZUl0ZW1zJGN0bDAwJGNieEFsbAVcY3RsMDAkUGxhY2VIb2xkZXJNYWluJGN0bDAwJF8kdXNyVmlld0NhcnRDb250cm9sJF8kY3RsMDAkXyRycHRMaW5lSXRlbXMkY3RsMDEkaW1nQnRuQ2F0ZWdvcnkFWmN0bDAwJFBsYWNlSG9sZGVyTWFpbiRjdGwwMCRfJHVzclZpZXdDYXJ0Q29udHJvbCRfJGN0bDAwJF8kcnB0TGluZUl0ZW1zJGN0bDAxJGNieFNlbGVjdGlvbgVoY3RsMDAkUGxhY2VIb2xkZXJNYWluJGN0bDAwJF8kdXNyVmlld0NhcnRDb250cm9sJF8kdXNyUHJvZHVjdFF1aWNrVmlld1BvcHVwJHVzclByb2R1Y3RRdWlja1ZpZXdQb3B1cF93bmQFG2N0bDAwJFBsYWNlSG9sZGVyTWFpbiRjdGwwMA8XAgULQ3VycmVudFZpZXcFCFZpZXdDYXJ0BQ1BY3RpdmVWaWV3U2V0Z2Q=,/wEPDwUBMGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgMFIWN0bDAxJF8kc...] 

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.] 

Répondre

5

J'ai trouvé le problème. En réponse à une demande ajax avec la Bibliothèque AjaxPro, je rends les contrôles comme soi-

Page page = new Page(); 

/*Not the exact way I init the control. But that's irrevelant*/ 
Control control = new Control(); 
page.Controls.Add(control) 
string controlHtml; 

using(StringWriter sw = new StringWriter()) 
{ 
    HttpContext.Current.Server.Execute(page, sw, false); 
    controlHtml = sw.ToString(); 
} 

Le problème avec cette approche est que asp .net TOUJOURS ajoute un champ caché pour viewstate. D'autres champs cachés comme eventtarget, eventargument, eventvalidation sont ajoutés en fonction des contrôles que contient votre page/contrôles. Ensuite, lorsque j'ajoute le code html résultant à un élément DOM existant du côté client, il y a bien évidemment des champs d'entrée cachés en double avec le même nom et l'identifiant résultant de la corruption de l'état d'affichage.

Solution?

Dénudez le code HTML généré de ces tags en utilisant regex (si vous êtes bon dans ce domaine) ou string compare/search etc.

0

On dirait peut être tronqué la demande de publication. Pouvez-vous vérifier la taille de ViewState?

1

Expression régulière pour remplacer le viewstate: returnValue = Regex.Replace (html, @ "< [/] (forme | [ovwxp]:? \ W +) [^>] *>", "", RegexOptions .IgnoreCase);

+1

Salut Hariharans87, bienvenue à StakOverflow. Cette question a été posée et répondue il y a près de 2 ans. Pensez-vous que votre réponse s'améliore ou contribue de quelque façon que ce soit à la réponse actuellement acceptée? –

0

vous avez deux form balises dans chaque page, retirez l'un d'entre eux et il décide:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="shop_test" %> 
<asp:Panel runat="server" ID="basketpanel" Visible="True"> 
    <form id="Form1" runat="server"> 
    </form> 
    </asp:Panel> 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="shop_test" %> 
<asp:Panel runat="server" ID="basketpanel" Visible="True"> 
    <form id="Form1" runat="server"> 
    </form> 
</asp:Panel> 
0

ajouter ces lignes à votre fichier cs et il va supprimer champ ViewState de sortie html:

protected override void Render(HtmlTextWriter output) 
    { 
     StringWriter stringWriter = new StringWriter(); 

     HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter); 
     base.Render(textWriter); 

     textWriter.Close(); 

     string strOutput = stringWriter.GetStringBuilder().ToString(); 

     strOutput = Regex.Replace(strOutput, "<input[^>]*id=\"__VIEWSTATE\"[^>]*>", "", RegexOptions.Singleline); 

     output.Write(strOutput); 
    } 
Questions connexes